06 July 2012 | | 5 notes | tags: , graduate school, industrial engineering, mathematics, milton l. smith, operations research, projects, random number generation, randomness, simulation, steve, texas tech, texas tech university, vba, random numbers, school, r, r package, r packages, r programming, open source, open source software, rng, random number generator, random number generators, mls, mls junk generator, mlsjunkgen, CRAN, rstats
photo credit: Irregular Shed
-[ background ]-
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 thought of it recently [07/2012] (not sure why) and decided to share.
[Update 02/2015] Now that I’m learning R, I decided to convert the generator to that language and clean-up and post the Excel/VBA versions I already had.
[Update 08/2015] This is now available as an R package (CRAN, GitHub).
-[ the mls junk generator ]-
For any seed values of w, x, y, z:
ri = 5.980217w^2 + 9.446377x^0.25 + 4.81379y^0.33 + 8.91197z^0.5
ri = ri - Int(ri)
For ri+1:
w = x
x = y
y = z
z = ri
-[ analysis ]-
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 (I gave up on trying to calculate it when it reached that point).
-[ vba code ]-
Here is an example of VBA code that generates a stream of random numbers in column A in Excel, assuming user-defined values of the parameters w, x, y, z, and n (the number of random numbers to generate) in cells C1 to C5. This can be downloaded in .xlsm or .bas format (see below).
-[ r code (aka MLS Junk GeneratR) ]-
In February 2015, I wrote two R functions with the same user-defined parameters as the VBA code above. The file (see below) also contains a version of this function that generates a data frame.
-[ r package (mlsjunkgen) ]-
mlsjunkgen is available on CRAN and can be installed accordingly:
install.packages("mlsjunkgen")
library(mlsjunkgen)
install.packages("devtools")
library(devtools)
install_github("scumdogsteev/mlsjunkgen")
library(mlsjunkgen)
junkgen generates a single pseudo-random number based on four user-specified seeds:
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:
mlsjunkgend generates a data frame containing a stream of n user-specified pseudo-random numbers based on four user-specified seeds:
mlsjunkgenm generates a matrix of user-specified size containing a stream of random numbers based on four user-specified seeds:
Releases:Versions of mlsjunkgen will be named after things related to Texas Tech University.
-[ license ]-
-[ project changelog ]-
2015-08-16
2015-02-01
2015-01-31
2012-07-06
Spring 2004
-[ download excel/vba implementation ]-
-[ download/install r package ]-
-[ download original r implementation ]-
[ all files ] | [ r source ]