This question already has an answer here:
I have been researching the source code of Rand() for a while, but until now I couldn't figure out the whole picture of the function.
The following are the source codes found and researched by me:
Could somebody provide some advices or assistance for me?
Thanks a million!
Rand is based on several things like mac address which should be unique on every machine. there are several implementations to verify that the returned value is "random"
It's not required to be based on any specific algorithm but many will use a linear congruential algorithm to generate the sequences. This basically changes the seed along the following lines:
and then deliver some portion of the seed as a random value. The values for
multiplier
,adder
andmodulo
can vary quite a bit.