Random Number Generator: Difference between revisions

Add Wichmann-Hill
[unchecked revision][unchecked revision]
(Add adversarial entropy from Nullplan's version)
(Add Wichmann-Hill)
Line 167:
 
Note that the seed must never be zero. This also means that it is never possible for all registers to have bit value zero, and that of the 2<sup>n</sup> possible combinations of registers, the all-zero state is not allowed. Therefore, 2<sup>n</sup> - 1 states is the maximum possible.
 
=== Wichmann-Hill ===
In 1982, Brian Wichmann and David Hill proposed to combine three linear congruential generators, then normalizing and summing the results to get a number uniformly distributed between 0 and 1. A common instance is:
 
<source lang="c">
static uint16_t seed[3]; /* seed with numbers between 1 and 30000 */
float wichmann_hill(void) {
seed[0] = (171 * seed[0]) % 30269;
seed[1] = (172 * seed[1]) % 30307;
seed[2] = (170 * seed[2]) % 30323;
return fmod(seed[0] / 30269.0 + seed[1] / 30307.0 + seed[2] / 30323.0, 1.0);
}</source>
 
This version is known to have a period of just shy of of seven trillion (the least common multiple of 30268, 30306, and 30322).
 
=== Mersenne Twister ===
Anonymous user