I understand that the C specification does not give any specification about the specific implementation of rand(). What different algorithms are commonly used on different major platforms? How do they differ?
I understand that the C specification does not give any specification about the specific
Share
See this article: http://en.wikipedia.org/wiki/List_of_random_number_generators
This is the source code of glibc’s
rand():Source: https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=stdlib/rand_r.c;hb=HEAD
As you can see, it’s simply multiply with an addition and a shift. The values are carefully chosen to make sure that you get no repeat of the output for RAND_MAX iterations.
Note that this is an old implementation which has been replaced by a more complex algorithm: https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=stdlib/random_r.c;hb=HEAD
If the link if broken, Google for “glibc rand_r”