State of the random number generator
Modulepcg-random-0.1.4.0Haskell2010
System.Random.PCG.Single
Single variant of the PCG random number generator. This module only uses a single stream. See http://www.pcg-random.org for details.
import Control.Monad.ST
import System.Random.PCG.Single
three :: [Double]
three = runST $ do
g <- create
a <- uniform g
b <- uniform g
c <- uniform g
return [a,b,c]
Synopsis
- newtype Gen
- type GenIO
- type GenST
- value create
- value createSystemRandom
- value initialize
- value withSystemRandom
- value withFrozen
- class Variate
- value advance
- value retract
- newtype 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
- SourceSingle.hs
Gen
Create a Gen from a fixed initial seed.
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 a single word.
initialize 0 >>= saveFrozenGen 1876011003808476466
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 g787992099create >>= \g -> replicateM_ 500 (uniformD g) >> uniformW32 g787992099create >>= \g -> advance 1000 g >> uniformW32 g787992099
Retract the given generator n steps in log(2^64-n) time. This
is just advance (-n).
create >>= \g -> replicateM 3 (uniformW32 g)[1499251125,2252584727,2021901712]create >>= \g -> retract 1 g >> replicateM 3 (uniformW32 g)[4031155981,1499251125,2252584727]
Seeds
Instances8Eq, Data, Ord, Show, Generic, Storable, …
Eq FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.SingleData FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.SingleOrd FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.SingleShow FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.SingleGeneric FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.SingleStorable FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.SingleRandomGen FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.Singletype Rep FrozenGen = D1 ('MetaDataDefined in pcg-random-0.1.4.0 · System.Random.PCG.Single"FrozenGen"
"System.Random.PCG.Single"
"pcg-random-0.1.4.0-LPPwvO63JO6GdQBtuVxy7K"
'True) (C1 ('MetaCons"FrozenGen"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
Standard initial seed.
Generate a new seed using single Word64.
initFrozen 0FrozenGen 1876011003808476466