State of the random number generator
Modulepcg-random-0.1.4.0Haskell2010
System.Random.PCG
Standard PCG Random Number Generator with chosen streams. See http://www.pcg-random.org for details.
import Control.Monad.ST
import System.Random.PCG
three :: [Double]
three = runST $ do
g <- create
a <- uniform g
b <- uniform g
c <- uniform g
return [a,b,c]
Contents
Synopsis
- newtype Gen
- type GenIO
- type GenST
- value create
- value createSystemRandom
- value initialize
- value withSystemRandom
- value withFrozen
- class Variate
- value advance
- value retract
- data FrozenGen
- value save
- value restore
- value seed
- value initFrozen
- value uniformW8
- value uniformW16
- value uniformW32
- value uniformW64
- value uniformI8
- value uniformI16
- value uniformI32
- value uniformI64
- value uniformF
- value uniformD
- value uniformBool
- value uniformRW8
- value uniformRW16
- value uniformRW32
- value uniformRW64
- value uniformRI8
- value uniformRI16
- value uniformRI32
- value uniformRI64
- value uniformRF
- value uniformRD
- value uniformRBool
- value uniformBW8
- value uniformBW16
- value uniformBW32
- value uniformBW64
- value uniformBI8
- value uniformBI16
- value uniformBI32
- value uniformBI64
- value uniformBF
- value uniformBD
- value uniformBBool
- Packagepcg-random-0.1.4.0
- Exports49
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourcePCG.hs
Generator
Seed a PRNG with data from the system's fast source of pseudo-random numbers. All the caveats of withSystemRandom apply here as well.
Initialize a generator with two words.
initialize 0 0 >>= saveFrozenGen 6364136223846793006 1
Seed with system random number. (/dev/urandom on Unix-like
systems and CryptAPI on Windows).
Run an action with a frozen generator, returning the result and the new frozen generator.
Getting random numbers
Methods
uniform :: Generator g m => g -> m aGenerate a uniformly distributed random vairate.
Use entire range for integral types.
Use (0,1] range for floating types.
uniformR :: Generator g m => (a, a) -> g -> m aGenerate a uniformly distributed random vairate in the given range.
Use inclusive range for integral types.
Use (a,b] range for floating types.
uniformB :: Generator g m => a -> g -> m aGenerate a uniformly distributed random vairate in the range [0,b). For integral types the bound must be less than the max bound of Word32 (4294967295). Behaviour is undefined for negative bounds.
Instances16Variate, …
Variate Int16Defined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate Int32Defined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate Int64Defined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate Int8Defined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate BoolDefined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate DoubleDefined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate FloatDefined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate IntDefined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate WordDefined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate Word16Defined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate Word32Defined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate Word64Defined in pcg-random-0.1.4.0 · System.Random.PCG.ClassVariate Word8Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class(Variate a, Variate b) => Variate (a, b)Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class(Variate a, Variate b, Variate c) => Variate (a, b, c)Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class(Variate a, Variate b, Variate c, Variate d) => Variate (a, b, c, d)Defined in pcg-random-0.1.4.0 · System.Random.PCG.Class
Advance the given generator n steps in log(n) time. (Note that a "step" is a single random 32-bit (or less) Variate. Data types such as Double or Word64 require two "steps".)
create >>= \g -> replicateM_ 1000 (uniformW32 g) >> uniformW32 g3640764222create >>= \g -> replicateM_ 500 (uniformD g) >> uniformW32 g3640764222create >>= \g -> advance 1000 g >> uniformW32 g3640764222
Retract the given generator n steps in log(2^64-n) time. This
is just advance (-n).
create >>= \g -> replicateM 3 (uniformW32 g)[355248013,41705475,3406281715]create >>= \g -> retract 1 g >> replicateM 3 (uniformW32 g)[19683962,355248013,41705475]
Frozen generator
Immutable snapshot of the state of a Gen.
Instances8Eq, Data, Ord, Show, Generic, Storable, …
Eq FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCGData FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCGOrd FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCGShow FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCGGeneric FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCGStorable FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCGRandomGen FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCGtype Rep FrozenGen = D1 ('MetaDataDefined in pcg-random-0.1.4.0 · System.Random.PCG"FrozenGen"
"System.Random.PCG"
"pcg-random-0.1.4.0-LPPwvO63JO6GdQBtuVxy7K"
'False) (C1 ('MetaCons"FrozenGen"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec0 Word64) :*: S1 ('MetaSel 'Nothing 'SourceUnpack 'SourceStrict 'DecidedUnpack) (Rec0 Word64)))
Fixed seed.
Generate a new seed using two Word64s.
initFrozen 0 0FrozenGen 6364136223846793006 1