| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Random.Source.StdGen
Contents
Description
This module provides functions useful for implementing new MonadRandom
and RandomSource instances for state-abstractions containing StdGen
values (the pure pseudorandom generator provided by the System.Random
module in the "random" package), as well as instances for some common
cases.
Synopsis
- data StdGen
- mkStdGen :: Int -> StdGen
- newStdGen :: MonadIO m => m StdGen
- getRandomPrimFromStdGenIO :: Prim a -> IO a
- getRandomPrimFromRandomGenRef :: (Monad m, ModifyRef sr m g, RandomGen g) => sr -> Prim a -> m a
- getRandomPrimFromRandomGenState :: forall g m a. (RandomGen g, MonadState g m) => Prim a -> m a
Documentation
The standard pseudo-random number generator.
Instances
newStdGen :: MonadIO m => m StdGen #
Applies split to the current global pseudo-random generator,
updates it with one of the results, and returns the other.
getRandomPrimFromStdGenIO :: Prim a -> IO a Source #
getRandomPrimFromRandomGenRef :: (Monad m, ModifyRef sr m g, RandomGen g) => sr -> Prim a -> m a Source #
Given a mutable reference to a RandomGen generator, we can make a
RandomSource usable in any monad in which the reference can be modified.
getRandomPrimFromRandomGenState :: forall g m a. (RandomGen g, MonadState g m) => Prim a -> m a Source #
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.
Orphan instances
| (Monad m, ModifyRef (STRef s StdGen) m StdGen) => RandomSource m (STRef s StdGen) Source # | |
Methods getRandomPrimFrom :: STRef s StdGen -> Prim t -> m t Source # getRandomWord8From :: STRef s StdGen -> m Word8 Source # getRandomWord16From :: STRef s StdGen -> m Word16 Source # getRandomWord32From :: STRef s StdGen -> m Word32 Source # getRandomWord64From :: STRef s StdGen -> m Word64 Source # getRandomDoubleFrom :: STRef s StdGen -> m Double Source # getRandomNByteIntegerFrom :: STRef s StdGen -> Int -> m Integer Source # | |