middle_square


middle_square, a C++ 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 computer code and data files made available on this web page are distributed under the MIT license

Languages:

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

Related Data and Programs:

middle_square_test

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

cpp_random_test, a C++ code which uses C's random number generators.

collatz_recursive, a C++ code which computes and analyzes the Collatz or hailstone or 3n+1 sequence, using a recursive approach;

cycle_brent, a C++ 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 C++ 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 C++ code which computes elements of a Halton quasirandom sequence.

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

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

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

ranlib, a C++ 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 C++ 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 C++ code which computes a sequence of uniformly distributed pseudorandom values.

van_der_corput, a C++ 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.