mwc-random-monad-0.4: Monadic interface for mwc-random

Safe HaskellNone




This module provide monadic interface for mwc-random package. It's just a thin wrapper and all work is done mwc-random.


Random monad

data Rand m a Source

Random monad for mwc-random package


toRand :: PrimMonad m => (Gen (PrimState m) -> m a) -> Rand m aSource

Convert function to Rand monad

liftR :: PrimMonad m => m a -> Rand m aSource

Lift monadic action into Rand monad

Type syhnonims

type RandIO a = Rand IO aSource

Type synonim for IO-based Rand monad

asRandIO :: RandIO a -> RandIO aSource

Fix type of monad to IO

type RandST s a = Rand (ST s) aSource

Type synonim for ST-based Rand monad

asRandST :: RandST s a -> RandST s aSource

Fix type of monad to ST

Running monad

runRand :: Rand m a -> Gen (PrimState m) -> m aSource

Run random monad

runWithCreate :: PrimMonad m => Rand m a -> m aSource

Run monad using fixed seed

runWithSeed :: PrimMonad m => Seed -> Rand m a -> m aSource

Run monad using seed

runWithVector :: (Vector v Word32, PrimMonad m) => Rand m a -> v Word32 -> m aSource

By creating seed from vector of values

runWithSystemRandom :: PrimMonad m => Rand m a -> IO aSource

Run monad using system random

Random numbers generation

uniform :: (PrimMonad m, Variate a) => Rand m aSource

Uniformly distributed values

uniformR :: (PrimMonad m, Variate a) => (a, a) -> Rand m aSource

Uniformly distributed values in range

Seed management

data Seed

An immutable snapshot of the state of a Gen.


toSeed :: Vector v Word32 => v Word32 -> Seed

Convert vector to Seed. It acts similarily to initialize and will accept any vector. If you want to pass seed immediately to restore you better call initialize directly since following law holds:

 restore (toSeed v) = initialize v

fromSeed :: Seed -> Vector Word32

Convert seed into vector.

save :: PrimMonad m => Rand m SeedSource

Save current seed for future reuse