Problem with rand()

May 14, 2008 at 3:22pm
I am writing a program that uses the rand() function to generate random numbers between 0 and 9. The problem is it is generating the same random numbers every time i load up my program.
Anyway I can stop this?
Thanks

Mark
May 14, 2008 at 4:53pm
At the beginning of your program use srand():
 
srand( time( NULL ) );


Hope this helps.
May 14, 2008 at 5:04pm
Sorted, for those who want to know I used this
srand ( time(NULL) );
To initialize it
http://www.cplusplus.com/reference/clibrary/cstdlib/rand.html
May 14, 2008 at 5:08pm
Ooh thanks.
I forgot to refresh the page to check whether someone had replied
Someone else told me, but thanks anyway.

Mark
Topic archived. No new replies allowed.