random-fu-0.0.2.1: Random number generationSource codeContentsIndex
Data.Random.Source.PureMT
Synopsis
getRandomWordFromMTRef :: ModifyRef sr m PureMT => sr -> m Word64
getRandomByteFromMTRef :: ModifyRef sr m PureMT => sr -> m Word8
getRandomDoubleFromMTRef :: ModifyRef sr m PureMT => sr -> m Double
getRandomWordFromMTState :: MonadState PureMT m => m Word64
getRandomByteFromMTState :: MonadState PureMT m => m Word8
getRandomDoubleFromMTState :: MonadState PureMT m => m Double
Documentation
getRandomWordFromMTRef :: ModifyRef sr m PureMT => sr -> m Word64Source

Given a mutable reference to a PureMT generator, we can make a RandomSource usable in any monad in which the reference can be modified.

For example, if x :: TVar PureMT, getRandomWordFromMTRef x can be used as a RandomSource in IO, STM, or any monad which is an instance of MonadIO. These functions can also be used to implement additional RandomSource instances for mutable references to PureMT states.

getRandomByteFromMTRef :: ModifyRef sr m PureMT => sr -> m Word8Source
getRandomDoubleFromMTRef :: ModifyRef sr m PureMT => sr -> m DoubleSource
getRandomWordFromMTState :: MonadState PureMT m => m Word64Source
Similarly, getRandomWordFromMTState x can be used in any "state" monad in the mtl sense whose state is a PureMT generator. Additionally, the standard mtl state monads have MonadRandom instances which do precisely that, allowing an easy conversion of RVars and other Distribution instances to "pure" random variables (e.g., by runState . sample :: Distribution d t => d t -> PureMT -> (t, PureMT). PureMT in the type there can be replaced by StdGen or anything else satisfying MonadRandom (State s) => s).
getRandomByteFromMTState :: MonadState PureMT m => m Word8Source
getRandomDoubleFromMTState :: MonadState PureMT m => m DoubleSource
Produced by Haddock version 2.4.2