randomWH API
Generation of Pseudo-Random Variates
|
This implements the algorithm described by Wichmann and Hill in
Two implementations are provided. One is for compilers that use 32 bits to store variables of the long int
type. A faster algorithm is also provided for use with compilers that feature a 64-bit long int
type. The algorithm to be used is determined automatically at run time.
The 64-bit version performs the following calculations:
\begin{align*} x &\leftarrow (11600 \times x) \bmod 2147483579 \\ y &\leftarrow (47003 \times y) \bmod 2147483543 \\ z &\leftarrow (23000 \times z) \bmod 2147483423 \\ t &\leftarrow (33000 \times t) \bmod 2147483123 \\ W &\leftarrow \frac{x}{2147483579}+\frac{y}{2147483543}+\frac{z}{2147483423}+\frac{t}{2147483123}\\ W &\leftarrow W-\lfloor W \rfloor\\ & \mbox{return } W \end{align*}
The 32-bit version calculates the same sequence, but as follows:
\begin{align*} x &\leftarrow 11600 \times (x \bmod 185127) - 10379 \times \left \lfloor \frac{x}{185127} \right \rfloor \\ y &\leftarrow 47003 \times (y \bmod 45688) - 10479 \times \left \lfloor \frac{y}{45688} \right \rfloor \\ z &\leftarrow 23000 \times (z \bmod 93368) - 19423 \times \left \lfloor \frac{z}{93368} \right \rfloor \\ t &\leftarrow 33000 \times (t \bmod 65075) - 8123 \times \left \lfloor \frac{t}{65075} \right \rfloor \\ x &\leftarrow \begin{cases} x & \text{ if } x \geq 0 \\ x + 2147483579 & \text{ if } x<0 \end{cases}\\ y &\leftarrow \begin{cases} y & \text{ if } y \geq 0 \\ y + 2147483579 & \text{ if } y<0 \end{cases}\\ z &\leftarrow \begin{cases} z & \text{ if } z \geq 0 \\ z + 2147483579 & \text{ if } z<0 \end{cases}\\ t &\leftarrow \begin{cases} t & \text{ if } t \geq 0 \\ t + 2147483579 & \text{ if } t<0 \end{cases}\\ W &\leftarrow \frac{x}{2147483579}+\frac{y}{2147483543}+\frac{z}{2147483423}+\frac{t}{2147483123} \end{align*}
\[ \mbox{return } W-\lfloor W \rfloor \]
Changes for v 0.3 alpha
congruence
to CongruenceCongruence
struct initialisation to avoid "sorry, unimplemented: non-trivial designated initializers not supported" error in g++ (C++, unlike C, does not support designated initializers - see here).message
argument from char*
to const
char*
Code will now compile without error or warnings in g++ as well as gcc (v2.8.1)