middle_square


middle_square, a Python code which implements the middle square algorithm for generating random integers. This is a very early method, attributed to von Neumann, which actually is deeply flawed, with short cycles.

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

middle_square is available in a C version and a C++ version and a Fortran90 version and a MATLAB version and an Octave version and a Python version.

Related Data and Programs:

asa183, a Python code which implements the Wichman-Hill random number generator (RNG).

collatz, a Python code which computes and analyzes the Collatz or hailstone or 3n+1 sequence;

cycle_brent, a Python code which carries out an iterated function evaluation, and seeks to determine the nearest element of a cycle, and the cycle length, using the Brent method.

cycle_floyd, a Python code which carries out an iterated function evaluation, and seeks to determine the nearest element of a cycle, and the cycle length, using the Floyd method.

halton, a Python code which computes elements of a Halton quasirandom sequence.

hammersley, a Python code which computes elements of a Hammersley quasirandom sequence.

normal, a Python code which computes a sequence of pseudorandom normally distributed values.

random_sorted, a Python code which generates vectors of random values which are already sorted.

ranlib, a Python code which produces random samples from Probability Density Functions (PDF's), including Beta, Chi-square Exponential, F, Gamma, Multivariate normal, Noncentral chi-square, Noncentral F, Univariate normal, random permutations, Real uniform, Binomial, Negative Binomial, Multinomial, Poisson and Integer uniform, by Barry Brown and James Lovato.

rnglib, a Python code which implements a random number generator (RNG) with splitting facilities, allowing multiple independent streams to be computed, by L'Ecuyer and Cote.

uniform, a Python code which computes a sequence of uniformly distributed pseudorandom values.

van_der_corput, a Python code which computes elements of a van der Corput quasirandom sequence.

Reference:

  1. Brian Hayes,
    The Middle of the Square,
    08 August 2022,
    http://bit-player.org/

Source Code:


Last modified on 16 September 2022.