No, you are supposed to use some type of timing function to ensure it
will not return the same series each time. The help page for rand()
shows you how.
--
Scott McPhillips [VC++ MVP]
void main( void )
{
int i;
/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) ); // YOU SHOULD INITIALIZE SEED !!!!
/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}
Moreover, if you develop multi-thread application and generate random
numbers in many threads, then you need to use srand() in each thread! In
this case you would need to think about other function than time() for
initial seed, as it measures time with 1 sec precision. And if you start two
or more threads within 1sec, than you again will receive identical
pseudo-random numbers generated.
I'd suggest using QueryPerformanceCounter() in this case.
"CLEAVEAGE" <iamcl...@shaw.ca> сообщил/сообщила в новостях следующее:
news:23FTa.496104$3C2.13...@news3.calgary.shaw.ca...
"Scott McPhillips" <scot...@mvps.org> wrote in message
news:3F1F30B9...@mvps.org...
HTH,
Wolfgang
"CLEAVEAGE" <iamcl...@shaw.ca> schrieb im Newsbeitrag
news:23FTa.496104$3C2.13...@news3.calgary.shaw.ca...