cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Problem with rand()
Problem with rand()
May 14, 2008 at 3:22pm UTC
mrmarky2
(12)
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 UTC
Duthomhas
(13212)
At the beginning of your program use
srand
():
srand( time( NULL ) );
Hope this helps.
May 14, 2008 at 5:04pm UTC
mrmarky2
(12)
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 UTC
mrmarky2
(12)
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.