+ 4
What does seed value signifies?
srand(98) what does that parameter indicates...?
2 odpowiedzi
+ 4
The number that is passed into srand is the number that random will use as its seed or starting point for the pseudo random number generating algorithm. If you use the same seed you'll get the same pattern of results from the PRNG every time. This is why most people use time(0) or time(NULL) to pass in the current system time in milliseconds which is constantly changing.
srand(time(NULL));
+ 2
Lets write our own random function to better understand it:
static unsigned int g_seed;
void srand(int seed)
{
g_seed = seed;
}
int rand()
{
g_seed = (214013*g_seed+2531011);
return (g_seed>>16)&0x7FFF;
}
The function needs a (seed) number to start off the algorithm.
Which is what srand provides.