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

Copyright(c) 2010-2012 Aleksey Khudyakov
LicenseBSD3
Maintaineralexey.skladnoy@gmail.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell98

System.Random.MWC.Monad

Contents

Description

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

Synopsis

Random monad

data Rand m a Source

Random monad for mwc-random package

Instances

toRand :: MonadPrim m => (Gen (PrimState (BasePrimMonad m)) -> BasePrimMonad m a) -> Rand m a Source

Convert function to Rand monad

Type syhnonims

type RandIO a = Rand IO a Source

Type synonim for IO-based Rand monad

asRandIO :: RandIO a -> RandIO a Source

Fix type of monad to IO

type RandST s a = Rand (ST s) a Source

Type synonim for ST-based Rand monad

asRandST :: RandST s a -> RandST s a Source

Fix type of monad to ST

Running monad

runRand :: Rand m a -> Gen (PrimState (BasePrimMonad m)) -> m a Source

Run random monad

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

Run monad using fixed seed

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

Run monad using seed

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

By creating seed from vector of values

runWithSystemRandom :: (PrimBase m, BasePrimMonad m ~ m) => Rand m a -> IO a Source

Run monad using seed obtained from system's fast source of pseudo-random numbers ("/dev/urandom" on Unix-like systems). m must be either IO or ST.

runWithSystemRandomT :: (MonadPrim m, BasePrimMonad m ~ IO) => Rand m a -> m a Source

Run monad using seed obtained from system's fast source of pseudo-random numbers ("/dev/urandom" on Unix-like systems). Unlike runWithSystemRandom it could be used with monad stacks.

Random numbers generation

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

Uniformly distributed values

uniformR :: (MonadPrim m, Variate a) => (a, a) -> Rand m a Source

Uniformly distributed values in range

Seed management

data Seed :: *

An immutable snapshot of the state of a Gen.

Instances

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 Seed Source

Save current seed for future reuse