using rand()

hi
in http://www.cplusplus.com/reference/clibrary/cstdlib/rand/ and in some thread of this forum there is are examplea for using the function rand in a way that should definitely be avoided.
generating uniform distributed random numbers fromthe set {0,1,2,...,m-1} should not be done with the expression "rand()%m" but with something like
"(int)(m*rand()/(MAX_RAND+1.0))"
(this is true for most other random generators)
the reason is that random generators are constraucted (and testet) that the most significant bits are random and not the least significant bits. it would be nice if you would correct this in your documentation.
It is true that LCRNGs have patterns in the low bits.

One can offset that by only using the higher bits, although this reduces the overall range of m.

However, in practice the LCRNG provided by the C runtime library should be avoided for
any RNG-critical programs.
Topic archived. No new replies allowed.