Anonymous user
Random number generator (included): Difference between revisions
→BSD rand(): n bits can contain only 2^n states whatever you do: it's the repeat length that matters
(→C rand(): The perils of BSD rand(): "This is not a real coin, and these are not truly random flips." The formula of Microsoft rand().) |
(→BSD rand(): n bits can contain only 2^n states whatever you do: it's the repeat length that matters) |
||
Line 81:
[[FreeBSD]] switched to a different formula, but [[NetBSD]] and [[OpenBSD]] stayed with this formula. ([http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdlib/rand.c?only_with_tag=MAIN NetBSD rand.c], [http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/rand.c OpenBSD rand.c])
BSD rand()
<lang c>#include <stdio.h>
Line 102:
* At odd seconds: tails, heads, tails, heads, tails, heads, tails, heads, tails, heads.
The low bit manages a uniform distribution between heads and tails, but it has a
In general, the low bits from BSD rand() are much less random than the high bits. This defect of BSD rand() is so famous that some programs ignore the low bits from rand().
|