VBScript program to generate pseudo random integers using a 32-bit Multiply With Carry generator. The
program outputs pseudo random integers equal to or greater than zero and less than 2^32. The period of
this generator is about 8.9 x 10^18, which is about 2^63.

The program accepts three optional parameters. The first is the number of pseudo random integers to
display. The default is 10. The second parameter is a seed value between zero and 2^32. The default is
a value based on the system timer. The third optional parameter is a carry value, also between zero and
2^32. The default carry if no value is supplied is a value based on the system date and time. The program
outputs integers greater than or equal to zero and less than 2^32.

The Multiply With Carry generator produces pseudo random integers according to the following:

Xi = [(A * Xi-1) + Ci-1] Mod M

Ci = Integer[((A * Xi-1) + Ci-1) / M]

Where:

Xi-1 is the previous integer (seed value)

Xi is the next integer

A = 4,164,903,690

M = 2^32 = 4,294,967,296 (the modulus)

Note:

B = (A * M) - 1 = 17,888,125,139,539,722,239

P = (B - 1) / 2 = 8,944,062,569,769,861,119

B and P are both prime.

The period of the generator is P.

Period =~ 8.944 * 10^18 =~ 2^63.

There are two cases where this generator will have a period of one. One case is when the initial seed
and carry are both zero. The other case is when the initial seed is M - 1 and the initial carry is A -1.
The program avoids both of these situations. The carry values produced by the generator are always less
than A. However, the initial carry can be equal to or greater than A. In that case, the initial pair of
values (seed and carry) will not be repeated.

The calculations involved to generate the pseudo random integers must be exact. There can be no round
off errors. Because VBScript can only represent integers exactly to 53 bits, special techniques are
required to handle intermediate calculations. The product A * Xi-1, for example, results in a 64 bit
value. The program handles this by breaking the integers into 16-bit high and low parts.

This Multiply With Carry generator passes all of the tests in the Diehard battery of tests of
randomness (by George Marsaglia).

MWC32.txt <<-- Click here to view or download the program