I took a course in graduate school ("Statistical Analysis for Digital Simulation") at Texas Tech from Dr. Elliot Montes in which we spent a lot of time on the generation and analysis of random numbers. Here is a simple-yet-powerful pseudo-random number generator that I learned about in that course. It is named "The MLS Junk Generator" after Dr. Milton L. Smith.
I have also released an Excel/VBA implementation and provided the simple R code used as the basis for this package.
For any seed values of w, x, y, z:
ri = 5.980217w2 + 9.446377x0.25 + 4.81379y0.33 + 8.91197z0.5
ri = ri - Int(ri)
For ri+1:
w = x
x = y
y = z
z = ri
This generator tends to do well with various tests for randomness (K-S, Chi Square, test for runs up and down). It may not perform as well on other tests (e.g., tests for runs above and below the mean), but that could relate to my choice of seeds. As a point of reference, the period of Excel's built-in random number generator is 16,777,216 (at least in Excel 2003; the algorithm may have changed in Excel 2007 or 2010 [Edit: this seems to still be the period of Excel's RNG.]) and the MLS Junk Generator's period is something greater than 9.9 billion
The package consists of four functions:
junkgen
- generates a pseudo-random number from user-specified seedsmlsjunkgenv
- generates a vector of pseudo-random numbers by calling
junkgen
a user-specified number of timesmlsjunkgend
- generates a data frame of pseudo-random numbers by calling
junkgen
a user-specified number of timesmlsjunkgenm
- generates a user-specified size matrix of pseudo-random
numbers by calling mlsjunkgenv
and assigning the results to a matrixlibrary(mlsjunkgen)
junkgen
generates a single pseudo-random number based on four user-specified
seeds:
w <- 1 x <- 2 y <- 3 z <- 4 junkgen(w = w, x = x, y = y, z = z)
mlsjunkgenv
generates a vector containing a stream of n
(default = 1)
user-specified pseudo-random numbers based on four user-specified seeds rounded
to a specified (default = 5) number of decimal places:
mlsjunkgenv(n = 10, w = w, x = x, y = y, z = z, round = 8)
The same example with default rounding:
mlsjunkgenv(n = 10, w = w, x = x, y = y, z = z)
mlsjunkgend
generates a data frame containing a stream of n
user-specified
pseudo-random numbers based on four user-specified seeds:
mlsjunkgend(n = 10, w = w, x = x, y = y, z = z, round = 8)
The same example with default rounding:
mlsjunkgend(n = 10, w = w, x = x, y = y, z = z)
mlsjunkgenm
generates a matrix of user-specified size containing a stream
of pseudo-random numbers based on four user-specified seeds:
mlsjunkgenm(nrow = 5, ncol = 5, w = w, x = x, y = y, z = z, round = 3)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.