mwc-random-monad-0.7: 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 :: MonadPrim m => (Gen (PrimState (BasePrimMonad m)) -> BasePrimMonad m a) -> Rand m aSource

Convert function to 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 (BasePrimMonad m)) -> m aSource

Run random monad

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

Run monad using fixed seed

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

Run monad using seed

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

By creating seed from vector of values

runWithSystemRandom :: (MonadPrim m, BasePrimMonad m ~ m) => Rand m a -> IO aSource

Run monad using system random

Random numbers generation

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

Uniformly distributed values

uniformR :: (MonadPrim 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 :: MonadPrim m => Rand m SeedSource

Save current seed for future reuse