State of the random number generator
Modulepcg-random-0.1.4.0Haskell2010
System.Random.PCG.Fast
Fast variant of the PCG random number generator. This module performs around 20% faster than the multiple streams version but produces slightly lower quality (still good) random numbers.
See http://www.pcg-random.org for details.
import Control.Monad.ST
import System.Random.PCG.Fast
three :: [Double]
three = runST $ do
g <- create
a <- uniform g
b <- uniform g
c <- uniform g
return [a,b,c]
- 4 types
- 1 class
- 44 values
- Packagepcg-random-0.1.4.0
- Exports49
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceFast.hs
Gen
8 declarationsCreate 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 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
3 declarationsMethods
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 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.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.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 g3725702568create >>= \g -> replicateM_ 500 (uniformD g) >> uniformW32 g3725702568create >>= \g -> advance 1000 g >> uniformW32 g3725702568
Retract the given generator n steps in log(2^64-n) time. This
is just advance (-n).
create >>= \g -> replicateM 3 (uniformW32 g)[2951688802,2698927131,361549788]create >>= \g -> retract 1 g >> replicateM 3 (uniformW32 g)[954135925,2951688802,2698927131]
Seeds
5 declarationsImmutable state of a random number generator. Suitable for storing for later use.
Instances8Eq, Data, Ord, Show, Generic, Storable, …
Eq FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.FastData FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.FastOrd FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.FastShow FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.FastGeneric FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.FastStorable FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.FastRandomGen FrozenGenDefined in pcg-random-0.1.4.0 · System.Random.PCG.Fasttype Rep FrozenGen = D1 ('MetaDataDefined in pcg-random-0.1.4.0 · System.Random.PCG.Fast"FrozenGen"
"System.Random.PCG.Fast"
"pcg-random-0.1.4.0-Bhb5XGfIMVVHgPMpu7qblw"
'True) (C1 ('MetaCons"FrozenGen"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word64)))
Save the state of a Gen in a Seed.
Restore a Gen from a Seed.
Standard initial seed.
Generate a new seed using single Word64.
initFrozen 0FrozenGen 1