| Copyright | (c) 2020 Naoyuki MORITA |
|---|---|
| License | BSD3 |
| Maintainer | naoyuki.morita@gmail.com |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
System.Random.MRG63k3a.Stateful
Contents
Description
Pseudo-random number generation with MRG63k3a [1] (monadic interface).
The generator type Gen is an instance of StatefulGen type class, so
it can be used through StatefulGen intreface functions such like,
> gen <-initialize1234567 > replicateM 10 (uniformMgen) :: IO [Word32] [2246106302,1563963788,2439712072,3737154441,2667077669,767817191,747111673,2638409746,3331088863,4075662417] > replicateM 10 (uniformMgen) :: IO [Word32] [1456421684,2935764772,936846699,649810874,4215441082,311517124,1039486180,751453058,3053799799,1547236802]
Gen: Pseudo-Random Number Generators
State of the pseudo-random number generator. It uses mutable state so same generator shouldn't be used from the different threads simultaneously.
Instances
| (s ~ PrimState m, PrimMonad m) => StatefulGen (Gen s) m Source # | |
Defined in System.Random.MRG63k3a.Stateful Methods uniformWord32R :: Word32 -> Gen s -> m Word32 # uniformWord64R :: Word64 -> Gen s -> m Word64 # uniformWord8 :: Gen s -> m Word8 # uniformWord16 :: Gen s -> m Word16 # uniformWord32 :: Gen s -> m Word32 # uniformWord64 :: Gen s -> m Word64 # uniformShortByteString :: Int -> Gen s -> m ShortByteString # | |
initialize :: PrimMonad m => Int64 -> m (Gen (PrimState m)) Source #
Create a generator using given seed.
Type helpers
Unitility functions
uniform01M :: PrimMonad m => Gen (PrimState m) -> m Double Source #
Get a random value following U(0,1).
Seed: state management
You can get the current PRNG state by freezeGen as an immutable data
that has type Seed. You may save the state into persistent store and
restore the state by thawGen later.
> gen <-initialize1234567 > replicateM 10 (uniform01Mgen) [0.9964374245717021,0.9073161749933566,0.308369875218738,0.2928356495081096,0.6407970127747293,0.8444224582886195,0.1358954027173811,0.4542392932876494,0.8016794723344877,0.8370627714083252] > seed <-freezeGengen > show $fromSeedseed "(8956691725955036650,4881994573324246905,544766949767175019,4767073730205058520,6711178582528615333,2047597627722241317)" > replicateM 10 (uniform01Mgen) [0.43854909685398463,0.3675952030734795,0.9681374152275398,0.7952475446049576,0.645021516355446,0.3490345515648514,0.13967842526828145,0.6463610214064653,0.3197503428491851,0.40268376160424424]
(in another context,)
> let seed =Seed$ read "(8956691725955036650,4881994573324246905,544766949767175019,4767073730205058520,6711178582528615333,2047597627722241317)" > gen <-thawGenseed > replicateM 10 (uniform01Mgen) [0.43854909685398463,0.3675952030734795,0.9681374152275398,0.7952475446049576,0.645021516355446,0.3490345515648514,0.13967842526828145,0.6463610214064653,0.3197503428491851,0.40268376160424424]
An immutable snapshot of the state of a Gen.
fromSeed :: Seed -> (Word64, Word64, Word64, Word64, Word64, Word64) Source #
Convert seed into a 6-tuple of Word64.
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