1970s Random Number Generator

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
zri

-[ 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 wxy, 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) ]-

Installation:
  • mlsjunkgen is available on CRAN and can be installed accordingly:

    install.packages("mlsjunkgen") library(mlsjunkgen)

  • updates to mlsjunkgen can be installed from GitHub using the devtools package:

    install.packages("devtools") library(devtools) install_github("scumdogsteev/mlsjunkgen") library(mlsjunkgen)

Functions
The package consists of four functions:
  1. junkgen - generates a pseudo-random number from user-specified seeds
  2. mlsjunkgenv - generates a vector of pseudo-random numbers by calling junkgen a user-specified number of times
  3. mlsjunkgend - generates a data frame of pseudo-random numbers by calling junkgen a user-specified number of times
  4. mlsjunkgenm - generates a user-specified size matrix of pseudo-random numbers by calling mlsjunkgenv and assigning the results to a matrix
Examples:

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

  • v0.1.0 of R package (Raider Red) created, see above for package release notes including subseuent versions

2015-02-01

  • files posted to GitHub
  • v.0.1.0 of Excel/VBA implementation released
  • R version created

2015-01-31

  • Excel files updated

2012-07-06

  • VBA code sample posted online

Spring 2004

  • VBA code written

-[ download excel/vba implementation ]-

[ releases ] | [ all files ]

  1. mls_junk_generator1.xlsm - simple Excel implementation
  2. mls_junk_generator.bas - VBA source for #1
  3. mls_junk_generator2.xlsm - second Excel implementation (allows for clearing of the RN stream)
  4. MLSJunkGen.bas - VBA module for #3

-[ download/install r package ]-

-[ download original r implementation ]-

[ all files ] | [ r source ]




Comments:

Notes:

  1. scumdogsteev reblogged this from scumdogsteev
blog comments powered by Disqus