| Copyright | (c) Brent Yorgey 2016 |
|---|---|
| License | BSD3 (see LICENSE) |
| Maintainer | byorgey@gmail.com |
| Stability | experimental |
| Portability | non-portable (multi-param classes, functional dependencies, undecidable instances) |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Control.Monad.Random.Strict
Description
Random monads that are strict in the generator state. For a lazy version, see Control.Monad.Random.Lazy, which has the same interface.
Synopsis
- type Rand g = RandT g Identity
- liftRand :: (g -> (a, g)) -> Rand g a
- runRand :: Rand g a -> g -> (a, g)
- evalRand :: Rand g a -> g -> a
- execRand :: Rand g a -> g -> g
- mapRand :: ((a, g) -> (b, g)) -> Rand g a -> Rand g b
- withRand :: (g -> g) -> Rand g a -> Rand g a
- evalRandIO :: Rand StdGen a -> IO a
- data RandT g (m :: Type -> Type) a
- liftRandT :: (g -> m (a, g)) -> RandT g m a
- runRandT :: RandT g m a -> g -> m (a, g)
- evalRandT :: Monad m => RandT g m a -> g -> m a
- execRandT :: Monad m => RandT g m a -> g -> m g
- mapRandT :: (m (a, g) -> n (b, g)) -> RandT g m a -> RandT g n b
- withRandT :: forall g (m :: Type -> Type) a. (g -> g) -> RandT g m a -> RandT g m a
- evalRandTIO :: MonadIO m => RandT StdGen m a -> m a
- class Random a where
- class Uniform a
- class Finite a
- class UniformRange a
- data StdGen
- class RandomGen g where
- next :: g -> (Int, g)
- genWord8 :: g -> (Word8, g)
- genWord16 :: g -> (Word16, g)
- genWord32 :: g -> (Word32, g)
- genWord64 :: g -> (Word64, g)
- genWord32R :: Word32 -> g -> (Word32, g)
- genWord64R :: Word64 -> g -> (Word64, g)
- genShortByteString :: Int -> g -> (ShortByteString, g)
- genRange :: g -> (Int, Int)
- split :: g -> (g, g)
- mkStdGen :: Int -> StdGen
- genByteString :: RandomGen g => Int -> g -> (ByteString, g)
- initStdGen :: MonadIO m => m StdGen
- setStdGen :: MonadIO m => StdGen -> m ()
- getStdGen :: MonadIO m => m StdGen
- newStdGen :: MonadIO m => m StdGen
- getStdRandom :: MonadIO m => (StdGen -> (a, StdGen)) -> m a
- randomRIO :: (Random a, MonadIO m) => (a, a) -> m a
- randomIO :: (Random a, MonadIO m) => m a
- module Control.Monad.Random.Class
- class Functor (f :: Type -> Type) where
- class Applicative m => Monad (m :: Type -> Type) where
- join :: Monad m => m (m a) -> m a
- liftM :: Monad m => (a1 -> r) -> m a1 -> m r
- class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where
- (=<<) :: Monad m => (a -> m b) -> m a -> m b
- mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
- sequence_ :: (Foldable t, Monad m) => t (m a) -> m ()
- mapM :: (Traversable t, Monad m) => (a -> m b) -> t a -> m (t b)
- sequence :: (Traversable t, Monad m) => t (m a) -> m (t a)
- ap :: Monad m => m (a -> b) -> m a -> m b
- liftM2 :: Monad m => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
- liftM3 :: Monad m => (a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
- liftM4 :: Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r
- liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r
- when :: Applicative f => Bool -> f () -> f ()
- (<$!>) :: Monad m => (a -> b) -> m a -> m b
- (<=<) :: Monad m => (b -> m c) -> (a -> m b) -> a -> m c
- (>=>) :: Monad m => (a -> m b) -> (b -> m c) -> a -> m c
- filterM :: Applicative m => (a -> m Bool) -> [a] -> m [a]
- foldM :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m b
- foldM_ :: (Foldable t, Monad m) => (b -> a -> m b) -> b -> t a -> m ()
- forever :: Applicative f => f a -> f b
- mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c])
- mfilter :: MonadPlus m => (a -> Bool) -> m a -> m a
- replicateM :: Applicative m => Int -> m a -> m [a]
- replicateM_ :: Applicative m => Int -> m a -> m ()
- unless :: Applicative f => Bool -> f () -> f ()
- zipWithM :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m [c]
- zipWithM_ :: Applicative m => (a -> b -> m c) -> [a] -> [b] -> m ()
- forM_ :: (Foldable t, Monad m) => t a -> (a -> m b) -> m ()
- msum :: (Foldable t, MonadPlus m) => t (m a) -> m a
- void :: Functor f => f a -> f ()
- forM :: (Traversable t, Monad m) => t a -> (a -> m b) -> m (t b)
- guard :: Alternative f => Bool -> f ()
- class Monad m => MonadFail (m :: Type -> Type) where
- fail :: String -> m a
- class Monad m => MonadFix (m :: Type -> Type) where
- mfix :: (a -> m a) -> m a
- fix :: (a -> a) -> a
- class (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) where
- class Monad m => MonadIO (m :: Type -> Type) where
- liftIO :: IO a -> m a
The Rand monad transformer
Arguments
| :: (g -> (a, g)) | pure random transformer |
| -> Rand g a | equivalent generator-passing computation |
Construct a random monad computation from a function.
(The inverse of runRand.)
Arguments
| :: Rand g a | generator-passing computation to execute |
| -> g | initial generator |
| -> (a, g) | return value and final generator |
Unwrap a random monad computation as a function.
(The inverse of liftRand.)
Arguments
| :: Rand g a | generator-passing computation to execute |
| -> g | initial generator |
| -> a | return value of the random computation |
Arguments
| :: Rand g a | generator-passing computation to execute |
| -> g | initial generator |
| -> g | final generator |
evalRandIO :: Rand StdGen a -> IO a Source #
Evaluate a random computation in the IO monad, splitting the global
standard generator to get a new one for the computation.
The RandT monad transformer
data RandT g (m :: Type -> Type) a Source #
A random transformer monad parameterized by:
g- The generator.m- The inner monad.
The return function leaves the generator unchanged, while >>= uses the
final generator of the first computation as the initial generator of the
second.
Instances
Arguments
| :: (g -> m (a, g)) | impure random transformer |
| -> RandT g m a | equivalent generator-passing computation |
Construct a random monad computation from an impure function.
(The inverse of runRandT.)
Arguments
| :: RandT g m a | generator-passing computation to execute |
| -> g | initial generator |
| -> m (a, g) | return value and final generator |
Unwrap a random monad computation as an impure function.
(The inverse of liftRandT.)
evalRandTIO :: MonadIO m => RandT StdGen m a -> m a Source #
Evaluate a random computation that is embedded in the IO monad,
splitting the global standard generator to get a new one for the
computation.
Some convenience re-exports
The class of types for which random values can be generated. Most
instances of Random will produce values that are uniformly distributed on the full
range, but for those types without a well-defined "full range" some sensible default
subrange will be selected.
Random exists primarily for backwards compatibility with version 1.1 of
this library. In new code, use the better specified Uniform and
UniformRange instead.
Since: random-1.0.0
Minimal complete definition
Nothing
Methods
randomR :: RandomGen g => (a, a) -> g -> (a, g) Source #
Takes a range (lo,hi) and a pseudo-random number generator g, and returns a pseudo-random value uniformly distributed over the closed interval [lo,hi], together with a new generator. It is unspecified what happens if lo>hi, but usually the values will simply get swapped.
>>>let gen = mkStdGen 2021>>>fst $ randomR ('a', 'z') gen't'>>>fst $ randomR ('z', 'a') gen't'
For continuous types there is no requirement that the values lo and hi are ever produced, but they may be, depending on the implementation and the interval.
There is no requirement to follow the Ord instance and the concept of range can be
defined on per type basis. For example product types will treat their values
independently:
>>>fst $ randomR (('a', 5.0), ('z', 10.0)) $ mkStdGen 2021('t',6.240232662366563)
In case when a lawful range is desired uniformR should be used
instead.
Since: random-1.0.0
default randomR :: (RandomGen g, UniformRange a) => (a, a) -> g -> (a, g) Source #
random :: RandomGen g => g -> (a, g) Source #
The same as randomR, but using a default range determined by the type:
- For bounded types (instances of
Bounded, such asChar), the range is normally the whole type. - For floating point types, the range is normally the closed interval
[0,1]. - For
Integer, the range is (arbitrarily) the range ofInt.
Since: random-1.0.0
randomRs :: RandomGen g => (a, a) -> g -> [a] Source #
Plural variant of randomR, producing an infinite list of
pseudo-random values instead of returning a new generator.
Since: random-1.0.0
randoms :: RandomGen g => g -> [a] Source #
Plural variant of random, producing an infinite list of
pseudo-random values instead of returning a new generator.
Since: random-1.0.0
Instances
| Random CBool | |
| Random CChar | |
| Random CDouble | Note - |
| Random CFloat | Note - |
| Random CInt | |
| Random CIntMax | |
| Random CIntPtr | |
| Random CLLong | |
| Random CLong | |
| Random CPtrdiff | |
| Random CSChar | |
| Random CShort | |
| Random CSigAtomic | |
Defined in System.Random | |
| Random CSize | |
| Random CUChar | |
| Random CUInt | |
| Random CUIntMax | |
| Random CUIntPtr | |
| Random CULLong | |
| Random CULong | |
| Random CUShort | |
| Random CWchar | |
| Random Int16 | |
| Random Int32 | |
| Random Int64 | |
| Random Int8 | |
| Random Word16 | |
| Random Word32 | |
| Random Word64 | |
| Random Word8 | |
| Random Integer | Note - |
| Random Bool | |
| Random Char | |
| Random Double | Note - |
| Random Float | Note - |
| Random Int | |
| Random Word | |
| (Random a, Random b) => Random (a, b) | Note - |
| (Random a, Random b, Random c) => Random (a, b, c) | Note - |
| (Random a, Random b, Random c, Random d) => Random (a, b, c, d) | Note - |
Defined in System.Random | |
| (Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e) | Note - |
| (Random a, Random b, Random c, Random d, Random e, Random f) => Random (a, b, c, d, e, f) | Note - |
Defined in System.Random Methods randomR :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> ((a, b, c, d, e, f), g) Source # random :: RandomGen g => g -> ((a, b, c, d, e, f), g) Source # randomRs :: RandomGen g => ((a, b, c, d, e, f), (a, b, c, d, e, f)) -> g -> [(a, b, c, d, e, f)] Source # randoms :: RandomGen g => g -> [(a, b, c, d, e, f)] Source # | |
| (Random a, Random b, Random c, Random d, Random e, Random f, Random g) => Random (a, b, c, d, e, f, g) | Note - |
Defined in System.Random Methods randomR :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> ((a, b, c, d, e, f, g), g0) Source # random :: RandomGen g0 => g0 -> ((a, b, c, d, e, f, g), g0) Source # randomRs :: RandomGen g0 => ((a, b, c, d, e, f, g), (a, b, c, d, e, f, g)) -> g0 -> [(a, b, c, d, e, f, g)] Source # randoms :: RandomGen g0 => g0 -> [(a, b, c, d, e, f, g)] Source # | |
The class of types for which a uniformly distributed value can be drawn from all possible values of the type.
Since: random-1.2.0
Instances
| Uniform CBool | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CBool Source # | |
| Uniform CChar | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CChar Source # | |
| Uniform CInt | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CInt Source # | |
| Uniform CIntMax | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CIntMax Source # | |
| Uniform CIntPtr | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CIntPtr Source # | |
| Uniform CLLong | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CLLong Source # | |
| Uniform CLong | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CLong Source # | |
| Uniform CPtrdiff | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CPtrdiff Source # | |
| Uniform CSChar | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CSChar Source # | |
| Uniform CShort | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CShort Source # | |
| Uniform CSigAtomic | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CSigAtomic Source # | |
| Uniform CSize | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CSize Source # | |
| Uniform CUChar | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CUChar Source # | |
| Uniform CUInt | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CUInt Source # | |
| Uniform CUIntMax | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CUIntMax Source # | |
| Uniform CUIntPtr | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CUIntPtr Source # | |
| Uniform CULLong | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CULLong Source # | |
| Uniform CULong | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CULong Source # | |
| Uniform CUShort | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CUShort Source # | |
| Uniform CWchar | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m CWchar Source # | |
| Uniform Int16 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Int16 Source # | |
| Uniform Int32 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Int32 Source # | |
| Uniform Int64 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Int64 Source # | |
| Uniform Int8 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Int8 Source # | |
| Uniform Word16 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word16 Source # | |
| Uniform Word32 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word32 Source # | |
| Uniform Word64 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word64 Source # | |
| Uniform Word8 | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word8 Source # | |
| Uniform () | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m () Source # | |
| Uniform Bool | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Bool Source # | |
| Uniform Char | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Char Source # | |
| Uniform Int | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Int Source # | |
| Uniform Word | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m Word Source # | |
| (Uniform a, Uniform b) => Uniform (a, b) | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m (a, b) Source # | |
| (Uniform a, Uniform b, Uniform c) => Uniform (a, b, c) | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m (a, b, c) Source # | |
| (Uniform a, Uniform b, Uniform c, Uniform d) => Uniform (a, b, c, d) | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m (a, b, c, d) Source # | |
| (Uniform a, Uniform b, Uniform c, Uniform d, Uniform e) => Uniform (a, b, c, d, e) | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m (a, b, c, d, e) Source # | |
| (Uniform a, Uniform b, Uniform c, Uniform d, Uniform e, Uniform f) => Uniform (a, b, c, d, e, f) | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g m => g -> m (a, b, c, d, e, f) Source # | |
| (Uniform a, Uniform b, Uniform c, Uniform d, Uniform e, Uniform f, Uniform g) => Uniform (a, b, c, d, e, f, g) | |
Defined in System.Random.Internal Methods uniformM :: StatefulGen g0 m => g0 -> m (a, b, c, d, e, f, g) Source # | |
A type class for data with a finite number of inhabitants.
This type class is used
in default implementations of Uniform.
Users are not supposed to write instances of Finite manually.
There is a default implementation in terms of Generic instead.
>>>:set -XDeriveGeneric -XDeriveAnyClass>>>import GHC.Generics (Generic)>>>data MyBool = MyTrue | MyFalse deriving (Generic, Finite)>>>data Action = Code MyBool | Eat (Maybe Bool) | Sleep deriving (Generic, Finite)
Instances
| Finite Void | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Void -> Cardinality toFinite :: Integer -> Void fromFinite :: Void -> Integer | |
| Finite Int16 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Int16 -> Cardinality toFinite :: Integer -> Int16 fromFinite :: Int16 -> Integer | |
| Finite Int32 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Int32 -> Cardinality toFinite :: Integer -> Int32 fromFinite :: Int32 -> Integer | |
| Finite Int64 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Int64 -> Cardinality toFinite :: Integer -> Int64 fromFinite :: Int64 -> Integer | |
| Finite Int8 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Int8 -> Cardinality toFinite :: Integer -> Int8 fromFinite :: Int8 -> Integer | |
| Finite Word16 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Word16 -> Cardinality toFinite :: Integer -> Word16 fromFinite :: Word16 -> Integer | |
| Finite Word32 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Word32 -> Cardinality toFinite :: Integer -> Word32 fromFinite :: Word32 -> Integer | |
| Finite Word64 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Word64 -> Cardinality toFinite :: Integer -> Word64 fromFinite :: Word64 -> Integer | |
| Finite Word8 | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Word8 -> Cardinality toFinite :: Integer -> Word8 fromFinite :: Word8 -> Integer | |
| Finite Ordering | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Ordering -> Cardinality toFinite :: Integer -> Ordering fromFinite :: Ordering -> Integer | |
| Finite () | |
Defined in System.Random.GFinite | |
| Finite Bool | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Bool -> Cardinality toFinite :: Integer -> Bool fromFinite :: Bool -> Integer | |
| Finite Char | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Char -> Cardinality toFinite :: Integer -> Char fromFinite :: Char -> Integer | |
| Finite Int | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Int -> Cardinality toFinite :: Integer -> Int fromFinite :: Int -> Integer | |
| Finite Word | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# Word -> Cardinality toFinite :: Integer -> Word fromFinite :: Word -> Integer | |
| Finite a => Finite (Maybe a) | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# (Maybe a) -> Cardinality toFinite :: Integer -> Maybe a fromFinite :: Maybe a -> Integer | |
| (Finite a, Finite b) => Finite (Either a b) | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# (Either a b) -> Cardinality toFinite :: Integer -> Either a b fromFinite :: Either a b -> Integer | |
| (Finite a, Finite b) => Finite (a, b) | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# (a, b) -> Cardinality toFinite :: Integer -> (a, b) fromFinite :: (a, b) -> Integer | |
| (Finite a, Finite b, Finite c) => Finite (a, b, c) | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# (a, b, c) -> Cardinality toFinite :: Integer -> (a, b, c) fromFinite :: (a, b, c) -> Integer | |
| (Finite a, Finite b, Finite c, Finite d) => Finite (a, b, c, d) | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# (a, b, c, d) -> Cardinality toFinite :: Integer -> (a, b, c, d) fromFinite :: (a, b, c, d) -> Integer | |
| (Finite a, Finite b, Finite c, Finite d, Finite e) => Finite (a, b, c, d, e) | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# (a, b, c, d, e) -> Cardinality toFinite :: Integer -> (a, b, c, d, e) fromFinite :: (a, b, c, d, e) -> Integer | |
| (Finite a, Finite b, Finite c, Finite d, Finite e, Finite f) => Finite (a, b, c, d, e, f) | |
Defined in System.Random.GFinite Methods cardinality :: Proxy# (a, b, c, d, e, f) -> Cardinality toFinite :: Integer -> (a, b, c, d, e, f) fromFinite :: (a, b, c, d, e, f) -> Integer | |
class UniformRange a Source #
The class of types for which a uniformly distributed value can be drawn from a range.
Since: random-1.2.0
Minimal complete definition
Instances
| UniformRange CBool | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CBool, CBool) -> g -> m CBool Source # | |
| UniformRange CChar | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CChar, CChar) -> g -> m CChar Source # | |
| UniformRange CDouble | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CDouble, CDouble) -> g -> m CDouble Source # | |
| UniformRange CFloat | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CFloat, CFloat) -> g -> m CFloat Source # | |
| UniformRange CInt | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CInt, CInt) -> g -> m CInt Source # | |
| UniformRange CIntMax | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CIntMax, CIntMax) -> g -> m CIntMax Source # | |
| UniformRange CIntPtr | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CIntPtr, CIntPtr) -> g -> m CIntPtr Source # | |
| UniformRange CLLong | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CLLong, CLLong) -> g -> m CLLong Source # | |
| UniformRange CLong | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CLong, CLong) -> g -> m CLong Source # | |
| UniformRange CPtrdiff | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CPtrdiff, CPtrdiff) -> g -> m CPtrdiff Source # | |
| UniformRange CSChar | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CSChar, CSChar) -> g -> m CSChar Source # | |
| UniformRange CShort | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CShort, CShort) -> g -> m CShort Source # | |
| UniformRange CSigAtomic | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CSigAtomic, CSigAtomic) -> g -> m CSigAtomic Source # | |
| UniformRange CSize | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CSize, CSize) -> g -> m CSize Source # | |
| UniformRange CUChar | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CUChar, CUChar) -> g -> m CUChar Source # | |
| UniformRange CUInt | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CUInt, CUInt) -> g -> m CUInt Source # | |
| UniformRange CUIntMax | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CUIntMax, CUIntMax) -> g -> m CUIntMax Source # | |
| UniformRange CUIntPtr | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CUIntPtr, CUIntPtr) -> g -> m CUIntPtr Source # | |
| UniformRange CULLong | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CULLong, CULLong) -> g -> m CULLong Source # | |
| UniformRange CULong | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CULong, CULong) -> g -> m CULong Source # | |
| UniformRange CUShort | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CUShort, CUShort) -> g -> m CUShort Source # | |
| UniformRange CWchar | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (CWchar, CWchar) -> g -> m CWchar Source # | |
| UniformRange Int16 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Int16, Int16) -> g -> m Int16 Source # | |
| UniformRange Int32 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Int32, Int32) -> g -> m Int32 Source # | |
| UniformRange Int64 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Int64, Int64) -> g -> m Int64 Source # | |
| UniformRange Int8 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Int8, Int8) -> g -> m Int8 Source # | |
| UniformRange Word16 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Word16, Word16) -> g -> m Word16 Source # | |
| UniformRange Word32 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Word32, Word32) -> g -> m Word32 Source # | |
| UniformRange Word64 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Word64, Word64) -> g -> m Word64 Source # | |
| UniformRange Word8 | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Word8, Word8) -> g -> m Word8 Source # | |
| UniformRange Integer | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Integer, Integer) -> g -> m Integer Source # | |
| UniformRange Natural | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Natural, Natural) -> g -> m Natural Source # | |
| UniformRange () | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => ((), ()) -> g -> m () Source # | |
| UniformRange Bool | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Bool, Bool) -> g -> m Bool Source # | |
| UniformRange Char | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Char, Char) -> g -> m Char Source # | |
| UniformRange Double | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Double, Double) -> g -> m Double Source # | |
| UniformRange Float | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Float, Float) -> g -> m Float Source # | |
| UniformRange Int | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Int, Int) -> g -> m Int Source # | |
| UniformRange Word | |
Defined in System.Random.Internal Methods uniformRM :: StatefulGen g m => (Word, Word) -> g -> m Word Source # | |
The standard pseudo-random number generator.
Instances
| NFData StdGen | |
Defined in System.Random.Internal | |
| Show StdGen | |
| Eq StdGen | |
| RandomGen StdGen | |
Defined in System.Random.Internal Methods next :: StdGen -> (Int, StdGen) Source # genWord8 :: StdGen -> (Word8, StdGen) Source # genWord16 :: StdGen -> (Word16, StdGen) Source # genWord32 :: StdGen -> (Word32, StdGen) Source # genWord64 :: StdGen -> (Word64, StdGen) Source # genWord32R :: Word32 -> StdGen -> (Word32, StdGen) Source # genWord64R :: Word64 -> StdGen -> (Word64, StdGen) Source # genShortByteString :: Int -> StdGen -> (ShortByteString, StdGen) Source # | |
| MonadSplit StdGen IO Source # | |
Defined in Control.Monad.Random.Class | |
class RandomGen g where Source #
RandomGen is an interface to pure pseudo-random number generators.
StdGen is the standard RandomGen instance provided by this library.
Since: random-1.0.0
Methods
next :: g -> (Int, g) Source #
Returns an Int that is uniformly distributed over the range returned by
genRange (including both end points), and a new generator. Using next
is inefficient as all operations go via Integer. See
here for
more details. It is thus deprecated.
Since: random-1.0.0
genWord8 :: g -> (Word8, g) Source #
Returns a Word8 that is uniformly distributed over the entire Word8
range.
Since: random-1.2.0
genWord16 :: g -> (Word16, g) Source #
Returns a Word16 that is uniformly distributed over the entire Word16
range.
Since: random-1.2.0
genWord32 :: g -> (Word32, g) Source #
Returns a Word32 that is uniformly distributed over the entire Word32
range.
Since: random-1.2.0
genWord64 :: g -> (Word64, g) Source #
Returns a Word64 that is uniformly distributed over the entire Word64
range.
Since: random-1.2.0
genWord32R :: Word32 -> g -> (Word32, g) Source #
genWord32R upperBound g returns a Word32 that is uniformly
distributed over the range [0, upperBound].
Since: random-1.2.0
genWord64R :: Word64 -> g -> (Word64, g) Source #
genWord64R upperBound g returns a Word64 that is uniformly
distributed over the range [0, upperBound].
Since: random-1.2.0
genShortByteString :: Int -> g -> (ShortByteString, g) Source #
genShortByteString n g returns a ShortByteString of length n
filled with pseudo-random bytes.
Since: random-1.2.0
genRange :: g -> (Int, Int) Source #
Yields the range of values returned by next.
It is required that:
- If
(a, b) =, thengenRangega < b. genRangemust not examine its argument so the value it returns is determined only by the instance ofRandomGen.
The default definition spans the full range of Int.
Since: random-1.0.0
Returns two distinct pseudo-random number generators.
Implementations should take care to ensure that the resulting generators
are not correlated. Some pseudo-random number generators are not
splittable. In that case, the split implementation should fail with a
descriptive error message.
Since: random-1.0.0
Instances
| RandomGen StdGen | |
Defined in System.Random.Internal Methods next :: StdGen -> (Int, StdGen) Source # genWord8 :: StdGen -> (Word8, StdGen) Source # genWord16 :: StdGen -> (Word16, StdGen) Source # genWord32 :: StdGen -> (Word32, StdGen) Source # genWord64 :: StdGen -> (Word64, StdGen) Source # genWord32R :: Word32 -> StdGen -> (Word32, StdGen) Source # genWord64R :: Word64 -> StdGen -> (Word64, StdGen) Source # genShortByteString :: Int -> StdGen -> (ShortByteString, StdGen) Source # | |
| RandomGen SMGen | |
Defined in System.Random.Internal Methods next :: SMGen -> (Int, SMGen) Source # genWord8 :: SMGen -> (Word8, SMGen) Source # genWord16 :: SMGen -> (Word16, SMGen) Source # genWord32 :: SMGen -> (Word32, SMGen) Source # genWord64 :: SMGen -> (Word64, SMGen) Source # genWord32R :: Word32 -> SMGen -> (Word32, SMGen) Source # genWord64R :: Word64 -> SMGen -> (Word64, SMGen) Source # genShortByteString :: Int -> SMGen -> (ShortByteString, SMGen) Source # | |
| RandomGen SMGen | |
Defined in System.Random.Internal Methods next :: SMGen -> (Int, SMGen) Source # genWord8 :: SMGen -> (Word8, SMGen) Source # genWord16 :: SMGen -> (Word16, SMGen) Source # genWord32 :: SMGen -> (Word32, SMGen) Source # genWord64 :: SMGen -> (Word64, SMGen) Source # genWord32R :: Word32 -> SMGen -> (Word32, SMGen) Source # genWord64R :: Word64 -> SMGen -> (Word64, SMGen) Source # genShortByteString :: Int -> SMGen -> (ShortByteString, SMGen) Source # | |
| RandomGen g => RandomGen (StateGen g) | |
Defined in System.Random.Internal Methods next :: StateGen g -> (Int, StateGen g) Source # genWord8 :: StateGen g -> (Word8, StateGen g) Source # genWord16 :: StateGen g -> (Word16, StateGen g) Source # genWord32 :: StateGen g -> (Word32, StateGen g) Source # genWord64 :: StateGen g -> (Word64, StateGen g) Source # genWord32R :: Word32 -> StateGen g -> (Word32, StateGen g) Source # genWord64R :: Word64 -> StateGen g -> (Word64, StateGen g) Source # genShortByteString :: Int -> StateGen g -> (ShortByteString, StateGen g) Source # | |
| RandomGen g => RandomGen (AtomicGen g) | |
Defined in System.Random.Stateful Methods next :: AtomicGen g -> (Int, AtomicGen g) Source # genWord8 :: AtomicGen g -> (Word8, AtomicGen g) Source # genWord16 :: AtomicGen g -> (Word16, AtomicGen g) Source # genWord32 :: AtomicGen g -> (Word32, AtomicGen g) Source # genWord64 :: AtomicGen g -> (Word64, AtomicGen g) Source # genWord32R :: Word32 -> AtomicGen g -> (Word32, AtomicGen g) Source # genWord64R :: Word64 -> AtomicGen g -> (Word64, AtomicGen g) Source # genShortByteString :: Int -> AtomicGen g -> (ShortByteString, AtomicGen g) Source # | |
| RandomGen g => RandomGen (IOGen g) | |
Defined in System.Random.Stateful Methods next :: IOGen g -> (Int, IOGen g) Source # genWord8 :: IOGen g -> (Word8, IOGen g) Source # genWord16 :: IOGen g -> (Word16, IOGen g) Source # genWord32 :: IOGen g -> (Word32, IOGen g) Source # genWord64 :: IOGen g -> (Word64, IOGen g) Source # genWord32R :: Word32 -> IOGen g -> (Word32, IOGen g) Source # genWord64R :: Word64 -> IOGen g -> (Word64, IOGen g) Source # genShortByteString :: Int -> IOGen g -> (ShortByteString, IOGen g) Source # | |
| RandomGen g => RandomGen (STGen g) | |
Defined in System.Random.Stateful Methods next :: STGen g -> (Int, STGen g) Source # genWord8 :: STGen g -> (Word8, STGen g) Source # genWord16 :: STGen g -> (Word16, STGen g) Source # genWord32 :: STGen g -> (Word32, STGen g) Source # genWord64 :: STGen g -> (Word64, STGen g) Source # genWord32R :: Word32 -> STGen g -> (Word32, STGen g) Source # genWord64R :: Word64 -> STGen g -> (Word64, STGen g) Source # genShortByteString :: Int -> STGen g -> (ShortByteString, STGen g) Source # | |
| RandomGen g => RandomGen (TGen g) | |
Defined in System.Random.Stateful Methods next :: TGen g -> (Int, TGen g) Source # genWord8 :: TGen g -> (Word8, TGen g) Source # genWord16 :: TGen g -> (Word16, TGen g) Source # genWord32 :: TGen g -> (Word32, TGen g) Source # genWord64 :: TGen g -> (Word64, TGen g) Source # genWord32R :: Word32 -> TGen g -> (Word32, TGen g) Source # genWord64R :: Word64 -> TGen g -> (Word64, TGen g) Source # genShortByteString :: Int -> TGen g -> (ShortByteString, TGen g) Source # | |
genByteString :: RandomGen g => Int -> g -> (ByteString, g) Source #
Generates a ByteString of the specified size using a pure pseudo-random
number generator. See uniformByteStringM for the monadic version.
Examples
>>>import System.Random>>>import Data.ByteString>>>let pureGen = mkStdGen 137>>>unpack . fst . genByteString 10 $ pureGen[51,123,251,37,49,167,90,109,1,4]
Since: random-1.2.0
initStdGen :: MonadIO m => m StdGen Source #
Initialize StdGen using system entropy (i.e. /dev/urandom) when it is
available, while falling back on using system time as the seed.
Since: random-1.2.1
setStdGen :: MonadIO m => StdGen -> m () Source #
Sets the global pseudo-random number generator. Overwrites the contents of
globalStdGen
Since: random-1.0.0
getStdGen :: MonadIO m => m StdGen Source #
Gets the global pseudo-random number generator. Extracts the contents of
globalStdGen
Since: random-1.0.0
newStdGen :: MonadIO m => m StdGen Source #
Applies split to the current global pseudo-random generator
globalStdGen, updates it with one of the results,
and returns the other.
Since: random-1.0.0
getStdRandom :: MonadIO m => (StdGen -> (a, StdGen)) -> m a Source #
Uses the supplied function to get a value from the current global
random generator, and updates the global generator with the new generator
returned by the function. For example, rollDice produces a pseudo-random integer
between 1 and 6:
>>>rollDice = getStdRandom (randomR (1, 6))>>>replicateM 10 (rollDice :: IO Int)[5,6,6,1,1,6,4,2,4,1]
This is an outdated function and it is recommended to switch to its
equivalent applyAtomicGen instead, possibly with the
globalStdGen if relying on the global state is
acceptable.
>>>import System.Random.Stateful>>>rollDice = applyAtomicGen (uniformR (1, 6)) globalStdGen>>>replicateM 10 (rollDice :: IO Int)[4,6,1,1,4,4,3,2,1,2]
Since: random-1.0.0
randomRIO :: (Random a, MonadIO m) => (a, a) -> m a Source #
A variant of randomRM that uses the global
pseudo-random number generator globalStdGen
>>>randomRIO (2020, 2100) :: IO Int2040
Similar to randomIO, this function is equivalent to and is included in this interface for historical reasons and
backwards compatibility. It is recommended to use
getStdRandom
randomRuniformRM instead, possibly with the
globalStdGen if relying on the global state is
acceptable.
>>>import System.Random.Stateful>>>uniformRM (2020, 2100) globalStdGen :: IO Int2079
Since: random-1.0.0
randomIO :: (Random a, MonadIO m) => m a Source #
A variant of randomM that uses the global
pseudo-random number generator globalStdGen.
>>>import Data.Int>>>randomIO :: IO Int32-1580093805
This function is equivalent to and is included in
this interface for historical reasons and backwards compatibility. It is
recommended to use getStdRandom randomuniformM instead, possibly with
the globalStdGen if relying on the global state is
acceptable.
>>>import System.Random.Stateful>>>uniformM globalStdGen :: IO Int32-1649127057
Since: random-1.0.0
module Control.Monad.Random.Class
class Functor (f :: Type -> Type) where #
Minimal complete definition
Instances
class Applicative m => Monad (m :: Type -> Type) where #
Minimal complete definition
Instances
| Monad Complex | |
| Monad First | |
| Monad Last | |
| Monad Max | |
| Monad Min | |
| Monad NonEmpty | |
| Monad Identity | |
| Monad First | |
| Monad Last | |
| Monad Dual | |
| Monad Product | |
| Monad Sum | |
| Monad Par1 | |
| Monad IO | |
| Monad Array | |
| Monad SmallArray | |
Defined in Data.Primitive.SmallArray Methods (>>=) :: SmallArray a -> (a -> SmallArray b) -> SmallArray b # (>>) :: SmallArray a -> SmallArray b -> SmallArray b # return :: a -> SmallArray a # | |
| Monad Q | |
| Monad Maybe | |
| Monad Solo | |
| Monad [] | |
| Monad m => Monad (WrappedMonad m) | |
| ArrowApply a => Monad (ArrowMonad a) | |
| Monad (Either e) | |
| Monad (U1 :: Type -> Type) | |
| Monad m => Monad (MaybeT m) | |
| Monoid a => Monad ((,) a) | |
| Monad m => Monad (RandT g m) Source # | |
| Monad m => Monad (RandT g m) Source # | |
| Monad m => Monad (Kleisli m a) | |
| Monad f => Monad (Ap f) | |
| Monad f => Monad (Alt f) | |
| Monad f => Monad (Rec1 f) | |
| Monad (t m) => Monad (LiftingAccum t m) | |
| Monad (t m) => Monad (LiftingSelect t m) | |
| (Monoid w, Functor m, Monad m) => Monad (AccumT w m) | |
| Monad m => Monad (ExceptT e m) | |
| Monad m => Monad (IdentityT m) | |
| Monad m => Monad (ReaderT r m) | |
| Monad m => Monad (SelectT r m) | |
| Monad m => Monad (StateT s m) | |
| Monad m => Monad (StateT s m) | |
| Monad m => Monad (WriterT w m) | |
| (Monoid w, Monad m) => Monad (WriterT w m) | |
| (Monoid w, Monad m) => Monad (WriterT w m) | |
| Monad m => Monad (Reverse m) | |
| (Monoid a, Monoid b) => Monad ((,,) a b) | |
| (Monad f, Monad g) => Monad (Product f g) | |
| (Monad f, Monad g) => Monad (f :*: g) | |
| Monad (ContT r m) | |
| (Monoid a, Monoid b, Monoid c) => Monad ((,,,) a b c) | |
| Monad ((->) r) | |
| Monad f => Monad (M1 i c f) | |
| Monad m => Monad (RWST r w s m) | |
| (Monoid w, Monad m) => Monad (RWST r w s m) | |
| (Monoid w, Monad m) => Monad (RWST r w s m) | |
class (Alternative m, Monad m) => MonadPlus (m :: Type -> Type) where #
Minimal complete definition
Nothing
Instances
liftM5 :: Monad m => (a1 -> a2 -> a3 -> a4 -> a5 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m a5 -> m r #
mapAndUnzipM :: Applicative m => (a -> m (b, c)) -> [a] -> m ([b], [c]) #
replicateM :: Applicative m => Int -> m a -> m [a] #
replicateM_ :: Applicative m => Int -> m a -> m () #
class Monad m => MonadFail (m :: Type -> Type) where #
Instances
class Monad m => MonadFix (m :: Type -> Type) where #
Instances
class (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) where #
Instances
class Monad m => MonadIO (m :: Type -> Type) where #