random-fu-0.0.1.1: Random number generationSource codeContentsIndex
Data.Random.Source.StdGen
Synopsis
getRandomByteFromStdGenIO :: IO Word8
getRandomWordFromStdGenIO :: IO Word64
getRandomDoubleFromStdGenIO :: IO Double
getRandomByteFromRandomGenRef :: (ModifyRef sr m g, RandomGen g) => sr -> m Word8
getRandomWordFromRandomGenRef :: (ModifyRef sr m g, RandomGen g) => sr -> m Word64
getRandomDoubleFromRandomGenRef :: (ModifyRef sr m g, RandomGen g) => sr -> m Double
getRandomByteFromRandomGenState :: (RandomGen g, MonadState g m) => m Word8
getRandomWordFromRandomGenState :: (RandomGen g, MonadState g m) => m Word64
getRandomDoubleFromRandomGenState :: (RandomGen g, MonadState g m) => m Double
Documentation
getRandomByteFromStdGenIO :: IO Word8Source
getRandomWordFromStdGenIO :: IO Word64Source
getRandomDoubleFromStdGenIO :: IO DoubleSource
getRandomByteFromRandomGenRef :: (ModifyRef sr m g, RandomGen g) => sr -> m Word8Source

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

For example, if x :: TVar StdGen, getRandomByteFromRandomGenRef x can be used as a RandomSource in IO, STM, or any monad which is an instance of MonadIO. It's generally probably better to use getRandomWordFromRandomGenRef though, as this one is likely to throw away a lot of perfectly good entropy. Better still is to use these 3 functions together to create a RandomSource instance for the reference you're using, if one does not already exist.

getRandomWordFromRandomGenRef :: (ModifyRef sr m g, RandomGen g) => sr -> m Word64Source
getRandomDoubleFromRandomGenRef :: (ModifyRef sr m g, RandomGen g) => sr -> m DoubleSource
getRandomByteFromRandomGenState :: (RandomGen g, MonadState g m) => m Word8Source
Similarly, getRandomWordFromRandomGenState x can be used in any "state" monad in the mtl sense whose state is a RandomGen 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.
getRandomWordFromRandomGenState :: (RandomGen g, MonadState g m) => m Word64Source
getRandomDoubleFromRandomGenState :: (RandomGen g, MonadState g m) => m DoubleSource
Produced by Haddock version 2.4.2