Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5
Computers are deterministic machines, and therefore have some major trouble with generating random numbers. You give it an algorithm and it's going to run it the same every time, because that's what computers do. So how do we get random numbers, then? One way is to provide an input to the randomization procedure-- That's what a "seed" is. If your seed is reasonably unpredictable, you'll have the illusion of randomness. srand is what allows you to specify a seed. You usually only need to specify a seed once, even though you can call rand() as often as you wish. A quick and easy seed value to use is the current time: srand(time(NULL));
6th Apr 2017, 2:52 AM
Squidy
Squidy - avatar