random numbers
Hi all,
I was just wondering how I would go about generating a sequence of random numbers that don't repeat each time the program restarts. rand() always repeats the exact same sequence each time the program is re-run and I was wondering how I might change that. I remember some time ago (at least 4 years) when there was a function called 'randomize' that made sure that the sequences were not repeated but I can't seem to find this function in c++ in linux. Any help is appreciated. |
Add srand(time(0)); to your program before any calls to rand(). You'll need to #include <time> and make sure you only call srand() one time. I usually add that line just after declaring variables in main().
|
cool! thanks a lot.
|
All times are GMT -5. The time now is 01:14 AM. |