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

System.Random.MWC.Monad

Contents

Synopsis

Random monad

data Rand m a Source

Random monad for mwc-random package

Instances

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

Lift monadic action into Rand monad

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

data Seed

An immutable snapshot of the state of a Gen.

Instances

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

Run random monad

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

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

Convert function to Rand monad

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

standard :: PrimMonad m => Rand m DoubleSource

Normally distributed variables with mean 0 and 1 standard deviation

normal :: PrimMonad m => Double -> Double -> Rand m DoubleSource

Normally distributed variable

Combining monads

equiprobable :: PrimMonad m => [Rand m a] -> Rand m aSource

Randomly select from list of equiprobable random sources. List must be non-empty

choices :: PrimMonad m => [(Double, Rand m a)] -> Rand m aSource

Randomly select from list of weighted random sources. List must contain sources with positive weight. Elements with non-positive weight are discarded

Seed management

save :: PrimMonad m => Rand m SeedSource

Save current seed for future reuse