mrg-random-0.1.0.0: Pseudo Random Number Generator with MRG (Multiple Recursive Generator)

Copyright(c) 2020 Naoyuki MORITA
LicenseBSD3
Maintainernaoyuki.morita@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

System.Random.MRG32k3a

Contents

Description

Pseudo-random number generation with MRG32k3a [1].

The generator type Gen is an instance of RandomGen type class, so it can be used through RandomGen intreface functions such like,

  > let g = initialize 12345
  > let (x, g') = uniform g :: (Word32, Gen) in x
  3320887301

Notice: MRG32k3a is originally designed to generate random numbers following U(0,1). It DOES NOT generate exactly 32-bit information at a time.

If you need U(0,1) random numbers, use uniform01 that generates a random value efficiently by original MRG32k3a algorithm.

Synopsis

Gen: Pseudo-Random Number Generators

data Gen Source #

The generator type.

Instances
RandomGen Gen Source # 
Instance details

Defined in System.Random.MRG32k3a

initialize :: Word32 -> Gen Source #

Create a generator using given seed.

Unitility functions

uniform01 :: Gen -> (Double, Gen) Source #

Get a random value following U(0,1).

Seed: state management

data Seed Source #

An immutable snapshot of the state of a Gen.

Instances
Eq Seed Source # 
Instance details

Defined in System.Random.MRG32k3a

Methods

(==) :: Seed -> Seed -> Bool #

(/=) :: Seed -> Seed -> Bool #

Show Seed Source # 
Instance details

Defined in System.Random.MRG32k3a

Methods

showsPrec :: Int -> Seed -> ShowS #

show :: Seed -> String #

showList :: [Seed] -> ShowS #

fromSeed :: Seed -> (Word32, Word32, Word32, Word32, Word32, Word32) Source #

Convert seed into a 6-tuple of Word32.

save :: Gen -> Seed Source #

Save the state of a Gen. Saved state can be used by restore.

restore :: Seed -> Gen Source #

Create a new Gen that mirrors the state of a saved Seed.

Stream jumping

jump :: Int -> Gen -> Gen Source #

Get a new generator jumps ahead by \(2^n\) steps from given generator.

  > let g0 = initialize 12345
  > let g1 = jump 20 g0
  > let xs = unfoldr (Just . uniform01) g0
  > let ys = unfoldr (Just . uniform01) g1
  > take 10 $ drop 1048576 xs
  [0.42963674510001276,0.10482156807623948,0.9889648413995019,0.785875227875553,0.9522150221887802,0.9792979233185687,0.8713777766671446,0.9231321178403405,0.13047652927672448,0.5395971153015737]
  > take 10 $ ys
  [0.42963674510001276,0.10482156807623948,0.9889648413995019,0.785875227875553,0.9522150221887802,0.9792979233185687,0.8713777766671446,0.9231321178403405,0.13047652927672448,0.5395971153015737]

References

[1] Pierre L'Ecuyer, (1999) Good Parameters and Implementations for Combined Multiple Recursive Random Number Generators.Operations Research 47(1):159-164. https://doi.org/10.1287/opre.47.1.159