Documentation

Batteries.Data.Random.MersenneTwister

Mersenne Twister #

Generic implementation for the Mersenne Twister pseudorandom number generator.

All choices of parameters from Matsumoto and Nishimura (1998) are supported, along with later refinements. Parameters for the standard 32-bit MT19937 and 64-bit MT19937-64 algorithms are provided. Both RandomGen and Stream interfaces are provided.

Use mt19937.init seed to create a MT19937 PRNG with a 32 bit seed value; use mt19937_64.init seed to create a MT19937-64 PRNG with a 64 bit seed value. If omitted, default seed choices will be used.

Sample usage:

import Batteries.Data.Random.MersenneTwister

open Batteries.Random.MersenneTwister

def mtgen := mt19937.init -- default seed 4357

#eval (Stream.take mtgen 5).fst -- [874448474, 2424656266, 2174085406, 1265871120, 3155244894]

References: #

Mersenne Twister configuration.

Letters in parentheses correspond to variable names used by Matsumoto and Nishimura (1998) and Nishimura (2000).

Instances For

    Mersenne Twister State.

    Instances For
      @[specialize #[0]]

      Mersenne Twister initialization given an optional seed.

      Equations
        Instances For
          @[irreducible]

          Inner loop for Mersenne Twister initalization.

          Equations
            Instances For
              @[specialize #[0]]

              Apply the twisting transformation to the given state.

              Equations
                Instances For
                  def Batteries.Random.MersenneTwister.State.update {cfg : Config} (state : State cfg) (steps : Nat := 1) :
                  State cfg

                  Update the state by a number of generation steps (default 1).

                  Equations
                    Instances For
                      @[specialize #[0]]

                      Mersenne Twister iteration.

                      Equations
                        Instances For
                          @[inline]

                          Tempering step for Mersenne Twister.

                          Equations
                            Instances For

                              32 bit Mersenne Twister (MT19937) configuration.

                              Equations
                                Instances For

                                  64 bit Mersenne Twister (MT19937-64) configuration.

                                  Equations
                                    Instances For