Wednesday, 6 July 2011

Randomness

So fairly early on into this project I discovered something about java.util.Random, its not random enough. Actually that's wrong, its actually plenty random enough for most simple applications such as the die rolls most computer rpgs simulate. But being a completionist I would need a better algorithm for use in Ancient Power.

A pseudorandom number generator (PRNG) can be measured by two main qualities its execution speed and its period . The period equates to the length of the sequence of numbers that it will produce before it begins repeating it's self.

The one I have decided to use is George Marsaglia's complementary-multiply-with-carry. This has both an extremely large period and, in its complementary implementation, fast execution.