I wanted to create a code that will generate a random number,
but I would like it if it would generate a different number from 1-6 each time.
this is what I began with:
cout << rand() %6 << endl;
now I read somewhere srand could be used, but that would be from RAND_MAX,
is there a way for a random number generator that would create a different number each time? thats out from a specific range?
Although I think you got what I was trying to say, allow me to be more specific...
I build and run the given code:
cout << rand() %6 << endl; //generates number from 1-6
and lets say I get 5.
After I close the program.
I build and run the program again and receive 5 again. and over and over.
I was wondering, if there is a way...where user's can get different random numbers each time. So the first time I might've gotten 5, but the next time I could get a 2 or a 4....
I understand that for the program the 5 might be a randomly generated number, but when its already a set, randomly generated number...it defeats the purpose.
I tried the given code you gave above....:
int main ()
cout << time << endl;
BUT....again...I am simply getting the same number over and over again...
any other suggestions?
thanks in advance!
What Chervil said it correct,
srand() seeds the random numbers, so when you use rand() it will give a different number.
ahhhhh I get it now!
thank you to both of you! Learning things everyday! :D