Alright, so im storing a random number to a variable using the GetRand function from the tutorial. What im wanting to do is get a different random number assigned to that variable..
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <ctime>
int GetRand(int min, int max)
{
static int Init = 0;
int rc;
if (Init == 0)
{
/*
* As Init is static, it will remember it's value between
* function calls. We only want srand() run once, so this
* is a simple way to ensure that happens.
*/
srand(time(NULL));
Init = 1;
}
/*
* Formula:
* rand() % N <- To get a number between 0 - N-1
* Then add the result to min, giving you
* a random number between min - max.
*/
rc = (rand() % (max - min + 1) + min);
return (rc);
}
int newnumber;
int number = getrand(1,12345);
int main()
{
cout<<"Your current random number is: "<<number<<endl;
cout<<"Enter '1' for a new number: ";
cin>>newnumber;
if(newnumber==1)
{
cout<<"Your new random number is: "<<number<<endl;
}
system("PAUSE");
return 0;
}
Please forgive the crude example program, im sure im missing a header or something. Id really appreciate any help that you all are willing to offer.