What does seed value signifies? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

What does seed value signifies?

srand(98) what does that parameter indicates...?

17th Jun 2017, 4:04 PM
Saajan Kumar Jha
Saajan Kumar Jha - avatar
2 Answers
+ 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));
17th Jun 2017, 4:39 PM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
17th Jun 2017, 4:42 PM
Dennis
Dennis - avatar