What's psuedo random number generator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What's psuedo random number generator?

I'm doing research on rand() function,but not getting how is it working if you know so you can share with me

25th Jan 2023, 7:03 AM
Datta Misal
Datta Misal - avatar
1 Answer
+ 4
Hi Ronny, The function rand() is a PRNG (psuedo random number generator). Psuedo just means that it's not a real/genuine random number, the reason being is that it's between a range 0-RAND_MAX (which is guaranteed to be atleast 32767). rand() requires a seed, which can be set by the srand() function, if you do not provide a seed it will automatically use 1. Multiple calls to rand() will generate the exact same sequence of numbers. Changing the seed guarantees a different set of random numbers (between the specified range). It's common to use time() as an arg for srand() so that each time it's called the set is in a different order. However using the same set can be useful for debugging.
25th Jan 2023, 10:23 AM
DavX
DavX - avatar