Hide
Free your code from a slow death on your hard drive Join Siafoo Now or Learn More

Wichmann-Hill Atom Feed 1

In Brief The Wichmann-Hill algorithm is a three seed pseudo-random number generator. The algorithm generates numbers between 0.0 and 1.0 with a cycle of . According to [Bevington] the algorithm is free of correlations and is a good generator for most purposes.... more
Implementation Difficulty * * * * *
 1 function get_random(seed_1, seed_2, seed_3):
2
3 seed_1 = 171 * (seed_1 % 177) - 2*(seed_1 / 177)
4
5 if seed_1 < 0: seed_1 += 30269
6
7 seed_2 = 172 * (seed_2 % 176) - 35*(seed_2 / 176)
8
9 if seed_2 < 0: seed_2 += 30307
10
11 seed_3 = 170 * (seed_3 % 178) - 63*(seed_3 / 178)
12
13 if seed_2 < 0: seed_2 += 30323
14
15 temp = seed_1 / 30269 + seed_2/30307 + seed_3/30323
16
17 return temp - int(temp)

The Wichmann-Hill algorithm is a three seed pseudo-random number generator. The algorithm generates numbers between 0.0 and 1.0 with a cycle of . According to [Bevington] the algorithm is free of correlations and is a good generator for most purposes.

[Bevington]
Philip Bevington, Data Reduction and Error Analysis for the Physical Sciences, McGraw-Hill Science/Engineering/Math
Implementations
A simple (unoptimized) implementation of the Wichmann-Hill pseudo-random number generator. The prng requires three seeds.