Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualfastcall22

Posted 15 November 2012 - 05:47 PM

How do I shuffle a sequence of random numbers that do not repeat

Hi Phil,

By default, the seed used by the random number generator is set to a default value each time the program starts. This causes the same sequence of random numbers. You will need to reseed the random number generator before using it.

Use the time function under the ctime header to get the current time (number of seconds since the epoch), then use that to seed the random number generator using srand:
srand( (unsigned)time(0) );

#1fastcall22

Posted 15 November 2012 - 05:46 PM

How do I shuffle a sequence of random numbers that do not repeat

Hi Phil,

By default, the seed used by the random number generator is set to a default value each time the program starts. This causes the same sequence of random numbers. You will need to reseed the random number generator before using it.

Use the time function under the http://www.cplusplus.com/reference/clibrary/ctime/ctime[/url] header to get the current time (number of seconds since the epoch), then use that to seed the random number generator using srand:
srand( (unsigned)time(0) );

PARTNERS