License | BSD-style |
---|---|
Stability | experimental |
Portability | Good |
Safe Haskell | None |
Language | Haskell2010 |
This module deals with the random subsystem abstractions.
It provide 2 different set of abstractions:
- The first abstraction that allow a monad to generate random
through the
MonadRandom
class. - The second abstraction to make generic random generator
RandomGen
and a small State monad like wrapperMonadRandomState
to abstract a generator.
- class (Functor m, Applicative m, Monad m) => MonadRandom m where
- class RandomGen gen where
- newtype MonadRandomState gen a = MonadRandomState {
- runRandomState :: gen -> (a, gen)
- withRandomGenerator :: RandomGen gen => gen -> MonadRandomState gen a -> (a, gen)
- type RNG = RNGv1
- type RNGv1 = State
Documentation
class (Functor m, Applicative m, Monad m) => MonadRandom m where #
A monad constraint that allows to generate random bytes
getRandomBytes :: CountOf Word8 -> m (UArray Word8) #
getRandomWord64 :: m Word64 #
getRandomF32 :: m Float #
getRandomF64 :: m Double #
MonadRandom IO # | |
RandomGen gen => MonadRandom (MonadRandomState gen) # | |
A Deterministic Random Generator (DRG) class
randomNew, randomNewFrom, randomGenerate, randomGenerateWord64, randomGenerateF32, randomGenerateF64
randomNew :: MonadRandom m => m gen #
Initialize a new random generator
randomNewFrom :: UArray Word8 -> Maybe gen #
Initialize a new random generator from a binary seed.
If Nothing
is returned, then the data is not acceptable
for creating a new random generator.
randomGenerate :: CountOf Word8 -> gen -> (UArray Word8, gen) #
Generate N bytes of randomness from a DRG
randomGenerateWord64 :: gen -> (Word64, gen) #
Generate a Word64 from a DRG
randomGenerateF32 :: gen -> (Float, gen) #
randomGenerateF64 :: gen -> (Double, gen) #
newtype MonadRandomState gen a #
A simple Monad class very similar to a State Monad with the state being a RandomGenerator.
MonadRandomState | |
|
Monad (MonadRandomState gen) # | |
Functor (MonadRandomState gen) # | |
Applicative (MonadRandomState gen) # | |
RandomGen gen => MonadRandom (MonadRandomState gen) # | |
withRandomGenerator :: RandomGen gen => gen -> MonadRandomState gen a -> (a, gen) #
Run a pure computation with a Random Generator in the MonadRandomState
An alias to the default choice of deterministic random number generator
Unless, you want to have the stability of a specific random number generator, e.g. for tests purpose, it's recommended to use this alias so that you would keep up to date with possible bugfixes, or change of algorithms.