tango.math.random.Kiss

License:

BSD style: see license.txt

Version:

Initial release: May 2008

Author:

Various

Since:

0.99.7

With gratitude to Dr Jurgen A Doornik. See his paper entitled "Conversion of high-period random numbers to floating point"
struct Kiss
KISS (from George Marsaglia)
The idea is to use simple, fast, individually promising generators to get a composite that will be fast, easy to code have a very long period and pass all the tests put to it. The three components of KISS are
1
2
3
x(n)=a*x(n-1)+1 mod 2^32
y(n)=y(n-1)(I+L^13)(I+R^17)(I+L^5),
z(n)=2*z(n-1)+z(n-2) +carry mod 2^32

The y's are a shift register sequence on 32bit binary vectors period 2^32-1; The z's are a simple multiply-with-carry sequence with period 2^63+2^32-1. The period of KISS is thus
1
2^32*(2^32-1)*(2^63+2^32-1) > 2^127

Note that this should be passed by reference, unless you really intend to provide a local copy to a callee
alias natural toInt
alias fraction toReal
Kiss instance [public, gshared, static]
A global, shared instance, seeded via startup time
Kiss opCall() [static]
Creates and seeds a new generator with the current time
void seed()
Seed the generator with current time
void seed(uint seed)
Seed the generator with a provided value
uint natural()
Returns X such that 0 <= X <= uint.max
uint natural(uint max)
Returns X such that 0 <= X < max
Note that max is exclusive, making it compatible with array indexing
uint natural(uint min, uint max)
Returns X such that min <= X < max
Note that max is exclusive, making it compatible with array indexing
double fraction()
Returns a value in the range [0, 1) using 32 bits of precision (with thanks to Dr Jurgen A Doornik)
double fractionEx()
Returns a value in the range [0, 1) using 52 bits of precision (with thanks to Dr Jurgen A Doornik)