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.MRG63k3a

Contents

Description

Pseudo-random number generation with MRG63k3a [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 1234567
  > let (x, g') = uniform g :: (Word32, Gen) in x
  2246106302
Synopsis

Gen: Pseudo-Random Number Generators

data Gen Source #

The generator type.

Instances
RandomGen Gen Source # 
Instance details

Defined in System.Random.MRG63k3a

initialize :: Int64 -> 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.MRG63k3a

Methods

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

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

Show Seed Source # 
Instance details

Defined in System.Random.MRG63k3a

Methods

showsPrec :: Int -> Seed -> ShowS #

show :: Seed -> String #

showList :: [Seed] -> ShowS #

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

Convert seed into a 6-tuple of Word64.

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 1234567
  > let g1 = jump 20 g0
  > let xs = unfoldr (Just . uniform01) g0
  > let ys = unfoldr (Just . uniform01) g1
  > take 10 $ drop 1048576 xs
  [0.8661862534637614,0.32299545841103733,0.7545203812431158,0.6829503373808978,0.7938803872652808,0.3453801891716969,0.199924353479426,0.7548724584148777,0.4533723232806143,0.855651888940174]
  > take 10 ys
  [0.8661862534637614,0.32299545841103733,0.7545203812431158,0.6829503373808978,0.7938803872652808,0.3453801891716969,0.199924353479426,0.7548724584148777,0.4533723232806143,0.855651888940174]

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