foundation-0.0.2: Alternative prelude with batteries and no dependencies

Safe HaskellNone



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 wrapper MonadRandomState to abstract a generator.



class (Functor m, Applicative m, Monad m) => MonadRandom m where Source #

A monad constraint that allows to generate random bytes

Minimal complete definition


newtype MonadRandomState gen a Source #

A simple Monad class very similar to a State Monad with the state being a RandomGenerator.




class RandomGen gen where Source #

A Deterministic Random Generator (DRG) class

Minimal complete definition

randomNew, randomGenerate


randomNew :: MonadRandom m => m gen Source #

Initialize a new random generator

randomGenerate :: Int -> gen -> (UArray Word8, gen) Source #

Generate N bytes of randomness from a DRG

withRandomGenerator :: RandomGen gen => gen -> MonadRandomState gen a -> (a, gen) Source #

Run a pure computation with a Random Generator in the MonadRandomState

type RNG = RNGv1 Source #

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.

data RNGv1 Source #

RNG based on ChaCha core.

The algorithm is identical to the arc4random found in recent BSDs, namely a ChaCha core provide 64 bytes of random from 32 bytes of key.