what is srand function?give me an example of its usage | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what is srand function?give me an example of its usage

22nd Jul 2019, 12:25 PM
Divyadharshini
Divyadharshini - avatar
2 Answers
0
it gives a seed random number srand(time(NULL); this use the time to give random number
22nd Jul 2019, 12:56 PM
✳AsterisK✳
✳AsterisK✳ - avatar
0
As most of us know that when we generate a random number by using "rand()" it'll always give us the same numbers over and over. By using "srand()" we get a random number but we should change the values inside the brackets of the srand. So our final solution to generate a random number without the need of changing the values inside the srand's brackets each time we use "time(0 or null)" inside the srand's brackets. This will generate random numbers every time we run our program.
29th Nov 2019, 7:58 PM
The unknown 321
The unknown 321 - avatar