{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE Trustworthy #-}
module System.Random
(
RandomGen(..)
, uniform
, uniformR
, genByteString
, Random(..)
, Uniform
, UniformRange
, Finite
, StdGen
, mkStdGen
, initStdGen
, getStdRandom
, getStdGen
, setStdGen
, newStdGen
, randomIO
, randomRIO
) where
import Control.Arrow
import Control.Monad.IO.Class
import Control.Monad.State.Strict
import Data.ByteString (ByteString)
import Data.Int
import Data.IORef
import Data.Word
import Foreign.C.Types
import GHC.Exts
import System.Random.GFinite (Finite)
import System.Random.Internal
import qualified System.Random.SplitMix as SM
uniform :: (RandomGen g, Uniform a) => g -> (a, g)
uniform :: forall g a. (RandomGen g, Uniform a) => g -> (a, g)
uniform g
g = g -> (StateGenM g -> State g a) -> (a, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g StateGenM g -> State g a
forall a g (m :: * -> *). (Uniform a, StatefulGen g m) => g -> m a
forall g (m :: * -> *). StatefulGen g m => g -> m a
uniformM
{-# INLINE uniform #-}
uniformR :: (RandomGen g, UniformRange a) => (a, a) -> g -> (a, g)
uniformR :: forall g a. (RandomGen g, UniformRange a) => (a, a) -> g -> (a, g)
uniformR (a, a)
r g
g = g -> (StateGenM g -> State g a) -> (a, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g ((a, a) -> StateGenM g -> State g a
forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
forall g (m :: * -> *). StatefulGen g m => (a, a) -> g -> m a
uniformRM (a, a)
r)
{-# INLINE uniformR #-}
genByteString :: RandomGen g => Int -> g -> (ByteString, g)
genByteString :: forall g. RandomGen g => Int -> g -> (ByteString, g)
genByteString Int
n g
g = g
-> (forall s. StateGenM g -> StateT g (ST s) ByteString)
-> (ByteString, g)
forall g a.
RandomGen g =>
g -> (forall s. StateGenM g -> StateT g (ST s) a) -> (a, g)
runStateGenST g
g (Int -> StateGenM g -> StateT g (ST s) ByteString
forall g (m :: * -> *). StatefulGen g m => Int -> g -> m ByteString
uniformByteStringM Int
n)
{-# INLINE genByteString #-}
class Random a where
{-# INLINE randomR #-}
randomR :: RandomGen g => (a, a) -> g -> (a, g)
default randomR :: (RandomGen g, UniformRange a) => (a, a) -> g -> (a, g)
randomR (a, a)
r g
g = g -> (StateGenM g -> State g a) -> (a, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g ((a, a) -> StateGenM g -> State g a
forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
forall g (m :: * -> *). StatefulGen g m => (a, a) -> g -> m a
uniformRM (a, a)
r)
{-# INLINE random #-}
random :: RandomGen g => g -> (a, g)
default random :: (RandomGen g, Uniform a) => g -> (a, g)
random g
g = g -> (StateGenM g -> State g a) -> (a, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g StateGenM g -> State g a
forall a g (m :: * -> *). (Uniform a, StatefulGen g m) => g -> m a
forall g (m :: * -> *). StatefulGen g m => g -> m a
uniformM
{-# INLINE randomRs #-}
randomRs :: RandomGen g => (a,a) -> g -> [a]
randomRs (a, a)
ival g
g = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\a -> b -> b
cons b
_nil -> (a -> b -> b) -> (g -> (a, g)) -> g -> b
forall g a as.
RandomGen g =>
(a -> as -> as) -> (g -> (a, g)) -> g -> as
buildRandoms a -> b -> b
cons ((a, a) -> g -> (a, g)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a, a)
ival) g
g)
{-# INLINE randoms #-}
randoms :: RandomGen g => g -> [a]
randoms g
g = (forall b. (a -> b -> b) -> b -> b) -> [a]
forall a. (forall b. (a -> b -> b) -> b -> b) -> [a]
build (\a -> b -> b
cons b
_nil -> (a -> b -> b) -> (g -> (a, g)) -> g -> b
forall g a as.
RandomGen g =>
(a -> as -> as) -> (g -> (a, g)) -> g -> as
buildRandoms a -> b -> b
cons g -> (a, g)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random g
g)
{-# INLINE buildRandoms #-}
buildRandoms :: RandomGen g
=> (a -> as -> as)
-> (g -> (a,g))
-> g
-> as
buildRandoms :: forall g a as.
RandomGen g =>
(a -> as -> as) -> (g -> (a, g)) -> g -> as
buildRandoms a -> as -> as
cons g -> (a, g)
rand = g -> as
go
where
go :: g -> as
go g
g = a
x a -> as -> as
forall a b. a -> b -> b
`seq` (a
x a -> as -> as
`cons` g -> as
go g
g') where (a
x,g
g') = g -> (a, g)
rand g
g
instance Random Integer where
random :: forall g. RandomGen g => g -> (Integer, g)
random = (Int -> Integer) -> (Int, g) -> (Integer, g)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first (Int -> Integer
forall a. Integral a => a -> Integer
toInteger :: Int -> Integer) ((Int, g) -> (Integer, g)) -> (g -> (Int, g)) -> g -> (Integer, g)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g -> (Int, g)
forall g. RandomGen g => g -> (Int, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance Random Int8
instance Random Int16
instance Random Int32
instance Random Int64
instance Random Int
instance Random Word
instance Random Word8
instance Random Word16
instance Random Word32
instance Random Word64
#if __GLASGOW_HASKELL__ >= 802
instance Random CBool
#endif
instance Random CChar
instance Random CSChar
instance Random CUChar
instance Random CShort
instance Random CUShort
instance Random CInt
instance Random CUInt
instance Random CLong
instance Random CULong
instance Random CPtrdiff
instance Random CSize
instance Random CWchar
instance Random CSigAtomic
instance Random CLLong
instance Random CULLong
instance Random CIntPtr
instance Random CUIntPtr
instance Random CIntMax
instance Random CUIntMax
instance Random CFloat where
randomR :: forall g. RandomGen g => (CFloat, CFloat) -> g -> (CFloat, g)
randomR (CFloat, CFloat)
r = (Float, g) -> (CFloat, g)
forall a b. Coercible a b => a -> b
coerce ((Float, g) -> (CFloat, g))
-> (g -> (Float, g)) -> g -> (CFloat, g)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Float, Float) -> g -> (Float, g)
forall g. RandomGen g => (Float, Float) -> g -> (Float, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR ((CFloat, CFloat) -> (Float, Float)
forall a b. Coercible a b => a -> b
coerce (CFloat, CFloat)
r :: (Float, Float))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> (CFloat, g)
random = (Float -> CFloat) -> (Float, g) -> (CFloat, g)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Float -> CFloat
CFloat ((Float, g) -> (CFloat, g))
-> (g -> (Float, g)) -> g -> (CFloat, g)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g -> (Float, g)
forall g. RandomGen g => g -> (Float, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance Random CDouble where
randomR :: forall g. RandomGen g => (CDouble, CDouble) -> g -> (CDouble, g)
randomR (CDouble, CDouble)
r = (Double, g) -> (CDouble, g)
forall a b. Coercible a b => a -> b
coerce ((Double, g) -> (CDouble, g))
-> (g -> (Double, g)) -> g -> (CDouble, g)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Double, Double) -> g -> (Double, g)
forall g. RandomGen g => (Double, Double) -> g -> (Double, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR ((CDouble, CDouble) -> (Double, Double)
forall a b. Coercible a b => a -> b
coerce (CDouble, CDouble)
r :: (Double, Double))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> (CDouble, g)
random = (Double -> CDouble) -> (Double, g) -> (CDouble, g)
forall b c d. (b -> c) -> (b, d) -> (c, d)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Double -> CDouble
CDouble ((Double, g) -> (CDouble, g))
-> (g -> (Double, g)) -> g -> (CDouble, g)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. g -> (Double, g)
forall g. RandomGen g => g -> (Double, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance Random Char
instance Random Bool
instance Random Double where
randomR :: forall g. RandomGen g => (Double, Double) -> g -> (Double, g)
randomR (Double, Double)
r g
g = g -> (StateGenM g -> State g Double) -> (Double, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g ((Double, Double) -> StateGenM g -> State g Double
forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
forall g (m :: * -> *).
StatefulGen g m =>
(Double, Double) -> g -> m Double
uniformRM (Double, Double)
r)
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> (Double, g)
random g
g = g -> (StateGenM g -> State g Double) -> (Double, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g ((Double -> Double) -> State g Double -> State g Double
forall a b. (a -> b) -> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
-) (State g Double -> State g Double)
-> (StateGenM g -> State g Double) -> StateGenM g -> State g Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateGenM g -> State g Double
forall g (m :: * -> *). StatefulGen g m => g -> m Double
uniformDouble01M)
{-# INLINE random #-}
instance Random Float where
randomR :: forall g. RandomGen g => (Float, Float) -> g -> (Float, g)
randomR (Float, Float)
r g
g = g -> (StateGenM g -> State g Float) -> (Float, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g ((Float, Float) -> StateGenM g -> State g Float
forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
forall g (m :: * -> *).
StatefulGen g m =>
(Float, Float) -> g -> m Float
uniformRM (Float, Float)
r)
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> (Float, g)
random g
g = g -> (StateGenM g -> State g Float) -> (Float, g)
forall g a.
RandomGen g =>
g -> (StateGenM g -> State g a) -> (a, g)
runStateGen g
g ((Float -> Float) -> State g Float -> State g Float
forall a b. (a -> b) -> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Float
1 Float -> Float -> Float
forall a. Num a => a -> a -> a
-) (State g Float -> State g Float)
-> (StateGenM g -> State g Float) -> StateGenM g -> State g Float
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StateGenM g -> State g Float
forall g (m :: * -> *). StatefulGen g m => g -> m Float
uniformFloat01M)
{-# INLINE random #-}
initStdGen :: MonadIO m => m StdGen
initStdGen :: forall (m :: * -> *). MonadIO m => m StdGen
initStdGen = IO StdGen -> m StdGen
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (SMGen -> StdGen
StdGen (SMGen -> StdGen) -> IO SMGen -> IO StdGen
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO SMGen
SM.initSMGen)
instance (Random a, Random b) => Random (a, b) where
randomR :: forall g. RandomGen g => ((a, b), (a, b)) -> g -> ((a, b), g)
randomR ((a
al, b
bl), (a
ah, b
bh)) = State g (a, b) -> g -> ((a, b), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b) -> g -> ((a, b), g))
-> State g (a, b) -> g -> ((a, b), g)
forall a b. (a -> b) -> a -> b
$
(,) (a -> b -> (a, b))
-> StateT g Identity a -> StateT g Identity (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((a, a) -> g -> (a, g)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
al, a
ah)) StateT g Identity (b -> (a, b))
-> StateT g Identity b -> State g (a, b)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((b, b) -> g -> (b, g)
forall g. RandomGen g => (b, b) -> g -> (b, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (b
bl, b
bh))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> ((a, b), g)
random = State g (a, b) -> g -> ((a, b), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b) -> g -> ((a, b), g))
-> State g (a, b) -> g -> ((a, b), g)
forall a b. (a -> b) -> a -> b
$ (,) (a -> b -> (a, b))
-> StateT g Identity a -> StateT g Identity (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (a, g)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (b -> (a, b))
-> StateT g Identity b -> State g (a, b)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (b, g)
forall g. RandomGen g => g -> (b, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance (Random a, Random b, Random c) => Random (a, b, c) where
randomR :: forall g.
RandomGen g =>
((a, b, c), (a, b, c)) -> g -> ((a, b, c), g)
randomR ((a
al, b
bl, c
cl), (a
ah, b
bh, c
ch)) = State g (a, b, c) -> g -> ((a, b, c), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c) -> g -> ((a, b, c), g))
-> State g (a, b, c) -> g -> ((a, b, c), g)
forall a b. (a -> b) -> a -> b
$
(,,) (a -> b -> c -> (a, b, c))
-> StateT g Identity a -> StateT g Identity (b -> c -> (a, b, c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((a, a) -> g -> (a, g)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
al, a
ah))
StateT g Identity (b -> c -> (a, b, c))
-> StateT g Identity b -> StateT g Identity (c -> (a, b, c))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((b, b) -> g -> (b, g)
forall g. RandomGen g => (b, b) -> g -> (b, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (b
bl, b
bh))
StateT g Identity (c -> (a, b, c))
-> StateT g Identity c -> State g (a, b, c)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((c, c) -> g -> (c, g)
forall g. RandomGen g => (c, c) -> g -> (c, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (c
cl, c
ch))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> ((a, b, c), g)
random = State g (a, b, c) -> g -> ((a, b, c), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c) -> g -> ((a, b, c), g))
-> State g (a, b, c) -> g -> ((a, b, c), g)
forall a b. (a -> b) -> a -> b
$ (,,) (a -> b -> c -> (a, b, c))
-> StateT g Identity a -> StateT g Identity (b -> c -> (a, b, c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (a, g)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (b -> c -> (a, b, c))
-> StateT g Identity b -> StateT g Identity (c -> (a, b, c))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (b, g)
forall g. RandomGen g => g -> (b, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (c -> (a, b, c))
-> StateT g Identity c -> State g (a, b, c)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (c, g)
forall g. RandomGen g => g -> (c, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance (Random a, Random b, Random c, Random d) => Random (a, b, c, d) where
randomR :: forall g.
RandomGen g =>
((a, b, c, d), (a, b, c, d)) -> g -> ((a, b, c, d), g)
randomR ((a
al, b
bl, c
cl, d
dl), (a
ah, b
bh, c
ch, d
dh)) = State g (a, b, c, d) -> g -> ((a, b, c, d), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d) -> g -> ((a, b, c, d), g))
-> State g (a, b, c, d) -> g -> ((a, b, c, d), g)
forall a b. (a -> b) -> a -> b
$
(,,,) (a -> b -> c -> d -> (a, b, c, d))
-> StateT g Identity a
-> StateT g Identity (b -> c -> d -> (a, b, c, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((a, a) -> g -> (a, g)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
al, a
ah))
StateT g Identity (b -> c -> d -> (a, b, c, d))
-> StateT g Identity b
-> StateT g Identity (c -> d -> (a, b, c, d))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((b, b) -> g -> (b, g)
forall g. RandomGen g => (b, b) -> g -> (b, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (b
bl, b
bh))
StateT g Identity (c -> d -> (a, b, c, d))
-> StateT g Identity c -> StateT g Identity (d -> (a, b, c, d))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((c, c) -> g -> (c, g)
forall g. RandomGen g => (c, c) -> g -> (c, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (c
cl, c
ch))
StateT g Identity (d -> (a, b, c, d))
-> StateT g Identity d -> State g (a, b, c, d)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((d, d) -> g -> (d, g)
forall g. RandomGen g => (d, d) -> g -> (d, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (d
dl, d
dh))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> ((a, b, c, d), g)
random = State g (a, b, c, d) -> g -> ((a, b, c, d), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d) -> g -> ((a, b, c, d), g))
-> State g (a, b, c, d) -> g -> ((a, b, c, d), g)
forall a b. (a -> b) -> a -> b
$
(,,,) (a -> b -> c -> d -> (a, b, c, d))
-> StateT g Identity a
-> StateT g Identity (b -> c -> d -> (a, b, c, d))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (a, g)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (b -> c -> d -> (a, b, c, d))
-> StateT g Identity b
-> StateT g Identity (c -> d -> (a, b, c, d))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (b, g)
forall g. RandomGen g => g -> (b, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (c -> d -> (a, b, c, d))
-> StateT g Identity c -> StateT g Identity (d -> (a, b, c, d))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (c, g)
forall g. RandomGen g => g -> (c, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (d -> (a, b, c, d))
-> StateT g Identity d -> State g (a, b, c, d)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (d, g)
forall g. RandomGen g => g -> (d, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance (Random a, Random b, Random c, Random d, Random e) => Random (a, b, c, d, e) where
randomR :: forall g.
RandomGen g =>
((a, b, c, d, e), (a, b, c, d, e)) -> g -> ((a, b, c, d, e), g)
randomR ((a
al, b
bl, c
cl, d
dl, e
el), (a
ah, b
bh, c
ch, d
dh, e
eh)) = State g (a, b, c, d, e) -> g -> ((a, b, c, d, e), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d, e) -> g -> ((a, b, c, d, e), g))
-> State g (a, b, c, d, e) -> g -> ((a, b, c, d, e), g)
forall a b. (a -> b) -> a -> b
$
(,,,,) (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> StateT g Identity a
-> StateT g Identity (b -> c -> d -> e -> (a, b, c, d, e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((a, a) -> g -> (a, g)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
al, a
ah))
StateT g Identity (b -> c -> d -> e -> (a, b, c, d, e))
-> StateT g Identity b
-> StateT g Identity (c -> d -> e -> (a, b, c, d, e))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((b, b) -> g -> (b, g)
forall g. RandomGen g => (b, b) -> g -> (b, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (b
bl, b
bh))
StateT g Identity (c -> d -> e -> (a, b, c, d, e))
-> StateT g Identity c
-> StateT g Identity (d -> e -> (a, b, c, d, e))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((c, c) -> g -> (c, g)
forall g. RandomGen g => (c, c) -> g -> (c, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (c
cl, c
ch))
StateT g Identity (d -> e -> (a, b, c, d, e))
-> StateT g Identity d -> StateT g Identity (e -> (a, b, c, d, e))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((d, d) -> g -> (d, g)
forall g. RandomGen g => (d, d) -> g -> (d, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (d
dl, d
dh))
StateT g Identity (e -> (a, b, c, d, e))
-> StateT g Identity e -> State g (a, b, c, d, e)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((e, e) -> g -> (e, g)
forall g. RandomGen g => (e, e) -> g -> (e, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (e
el, e
eh))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> ((a, b, c, d, e), g)
random = State g (a, b, c, d, e) -> g -> ((a, b, c, d, e), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d, e) -> g -> ((a, b, c, d, e), g))
-> State g (a, b, c, d, e) -> g -> ((a, b, c, d, e), g)
forall a b. (a -> b) -> a -> b
$
(,,,,) (a -> b -> c -> d -> e -> (a, b, c, d, e))
-> StateT g Identity a
-> StateT g Identity (b -> c -> d -> e -> (a, b, c, d, e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (a, g)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (b -> c -> d -> e -> (a, b, c, d, e))
-> StateT g Identity b
-> StateT g Identity (c -> d -> e -> (a, b, c, d, e))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (b, g)
forall g. RandomGen g => g -> (b, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (c -> d -> e -> (a, b, c, d, e))
-> StateT g Identity c
-> StateT g Identity (d -> e -> (a, b, c, d, e))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (c, g)
forall g. RandomGen g => g -> (c, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (d -> e -> (a, b, c, d, e))
-> StateT g Identity d -> StateT g Identity (e -> (a, b, c, d, e))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (d, g)
forall g. RandomGen g => g -> (d, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random StateT g Identity (e -> (a, b, c, d, e))
-> StateT g Identity e -> State g (a, b, c, d, e)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (e, g)
forall g. RandomGen g => g -> (e, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance (Random a, Random b, Random c, Random d, Random e, Random f) =>
Random (a, b, c, d, e, f) where
randomR :: forall g.
RandomGen g =>
((a, b, c, d, e, f), (a, b, c, d, e, f))
-> g -> ((a, b, c, d, e, f), g)
randomR ((a
al, b
bl, c
cl, d
dl, e
el, f
fl), (a
ah, b
bh, c
ch, d
dh, e
eh, f
fh)) = State g (a, b, c, d, e, f) -> g -> ((a, b, c, d, e, f), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d, e, f) -> g -> ((a, b, c, d, e, f), g))
-> State g (a, b, c, d, e, f) -> g -> ((a, b, c, d, e, f), g)
forall a b. (a -> b) -> a -> b
$
(,,,,,) (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity a
-> StateT g Identity (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((a, a) -> g -> (a, g)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
al, a
ah))
StateT g Identity (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity b
-> StateT g Identity (c -> d -> e -> f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((b, b) -> g -> (b, g)
forall g. RandomGen g => (b, b) -> g -> (b, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (b
bl, b
bh))
StateT g Identity (c -> d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity c
-> StateT g Identity (d -> e -> f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((c, c) -> g -> (c, g)
forall g. RandomGen g => (c, c) -> g -> (c, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (c
cl, c
ch))
StateT g Identity (d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity d
-> StateT g Identity (e -> f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((d, d) -> g -> (d, g)
forall g. RandomGen g => (d, d) -> g -> (d, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (d
dl, d
dh))
StateT g Identity (e -> f -> (a, b, c, d, e, f))
-> StateT g Identity e
-> StateT g Identity (f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((e, e) -> g -> (e, g)
forall g. RandomGen g => (e, e) -> g -> (e, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (e
el, e
eh))
StateT g Identity (f -> (a, b, c, d, e, f))
-> StateT g Identity f -> State g (a, b, c, d, e, f)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((f, f) -> g -> (f, g)
forall g. RandomGen g => (f, f) -> g -> (f, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (f
fl, f
fh))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> ((a, b, c, d, e, f), g)
random = State g (a, b, c, d, e, f) -> g -> ((a, b, c, d, e, f), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d, e, f) -> g -> ((a, b, c, d, e, f), g))
-> State g (a, b, c, d, e, f) -> g -> ((a, b, c, d, e, f), g)
forall a b. (a -> b) -> a -> b
$
(,,,,,) (a -> b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity a
-> StateT g Identity (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (a, g)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (b -> c -> d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity b
-> StateT g Identity (c -> d -> e -> f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (b, g)
forall g. RandomGen g => g -> (b, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (c -> d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity c
-> StateT g Identity (d -> e -> f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (c, g)
forall g. RandomGen g => g -> (c, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (d -> e -> f -> (a, b, c, d, e, f))
-> StateT g Identity d
-> StateT g Identity (e -> f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (d, g)
forall g. RandomGen g => g -> (d, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (e -> f -> (a, b, c, d, e, f))
-> StateT g Identity e
-> StateT g Identity (f -> (a, b, c, d, e, f))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (e, g)
forall g. RandomGen g => g -> (e, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (f -> (a, b, c, d, e, f))
-> StateT g Identity f -> State g (a, b, c, d, e, f)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (f, g)
forall g. RandomGen g => g -> (f, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance (Random a, Random b, Random c, Random d, Random e, Random f, Random g) =>
Random (a, b, c, d, e, f, g) where
randomR :: forall g.
RandomGen g =>
((a, b, c, d, e, f, g), (a, b, c, d, e, f, g))
-> g -> ((a, b, c, d, e, f, g), g)
randomR ((a
al, b
bl, c
cl, d
dl, e
el, f
fl, g
gl), (a
ah, b
bh, c
ch, d
dh, e
eh, f
fh, g
gh)) = State g (a, b, c, d, e, f, g) -> g -> ((a, b, c, d, e, f, g), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d, e, f, g) -> g -> ((a, b, c, d, e, f, g), g))
-> State g (a, b, c, d, e, f, g) -> g -> ((a, b, c, d, e, f, g), g)
forall a b. (a -> b) -> a -> b
$
(,,,,,,) (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity a
-> StateT
g Identity (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((a, a) -> g -> (a, g)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a
al, a
ah))
StateT
g Identity (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity b
-> StateT
g Identity (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((b, b) -> g -> (b, g)
forall g. RandomGen g => (b, b) -> g -> (b, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (b
bl, b
bh))
StateT g Identity (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity c
-> StateT g Identity (d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((c, c) -> g -> (c, g)
forall g. RandomGen g => (c, c) -> g -> (c, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (c
cl, c
ch))
StateT g Identity (d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity d
-> StateT g Identity (e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((d, d) -> g -> (d, g)
forall g. RandomGen g => (d, d) -> g -> (d, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (d
dl, d
dh))
StateT g Identity (e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity e
-> StateT g Identity (f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((e, e) -> g -> (e, g)
forall g. RandomGen g => (e, e) -> g -> (e, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (e
el, e
eh))
StateT g Identity (f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity f
-> StateT g Identity (g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((f, f) -> g -> (f, g)
forall g. RandomGen g => (f, f) -> g -> (f, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (f
fl, f
fh))
StateT g Identity (g -> (a, b, c, d, e, f, g))
-> StateT g Identity g -> State g (a, b, c, d, e, f, g)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (g, g)) -> StateT g Identity g
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((g, g) -> g -> (g, g)
forall g. RandomGen g => (g, g) -> g -> (g, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (g
gl, g
gh))
{-# INLINE randomR #-}
random :: forall g. RandomGen g => g -> ((a, b, c, d, e, f, g), g)
random = State g (a, b, c, d, e, f, g) -> g -> ((a, b, c, d, e, f, g), g)
forall s a. State s a -> s -> (a, s)
runState (State g (a, b, c, d, e, f, g) -> g -> ((a, b, c, d, e, f, g), g))
-> State g (a, b, c, d, e, f, g) -> g -> ((a, b, c, d, e, f, g), g)
forall a b. (a -> b) -> a -> b
$
(,,,,,,) (a -> b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity a
-> StateT
g Identity (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (g -> (a, g)) -> StateT g Identity a
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (a, g)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT
g Identity (b -> c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity b
-> StateT
g Identity (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (b, g)
forall g. RandomGen g => g -> (b, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (c -> d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity c
-> StateT g Identity (d -> e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (c, g)
forall g. RandomGen g => g -> (c, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (d -> e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity d
-> StateT g Identity (e -> f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (d, g)
forall g. RandomGen g => g -> (d, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (e -> f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity e
-> StateT g Identity (f -> g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (e, g)
forall g. RandomGen g => g -> (e, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (f -> g -> (a, b, c, d, e, f, g))
-> StateT g Identity f
-> StateT g Identity (g -> (a, b, c, d, e, f, g))
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (f, g)
forall g. RandomGen g => g -> (f, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
StateT g Identity (g -> (a, b, c, d, e, f, g))
-> StateT g Identity g -> State g (a, b, c, d, e, f, g)
forall a b.
StateT g Identity (a -> b)
-> StateT g Identity a -> StateT g Identity b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (g, g)) -> StateT g Identity g
forall a. (g -> (a, g)) -> StateT g Identity a
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (g, g)
forall g. RandomGen g => g -> (g, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
setStdGen :: MonadIO m => StdGen -> m ()
setStdGen :: forall (m :: * -> *). MonadIO m => StdGen -> m ()
setStdGen = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> (StdGen -> IO ()) -> StdGen -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef StdGen -> StdGen -> IO ()
forall a. IORef a -> a -> IO ()
writeIORef IORef StdGen
theStdGen
getStdGen :: MonadIO m => m StdGen
getStdGen :: forall (m :: * -> *). MonadIO m => m StdGen
getStdGen = IO StdGen -> m StdGen
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO StdGen -> m StdGen) -> IO StdGen -> m StdGen
forall a b. (a -> b) -> a -> b
$ IORef StdGen -> IO StdGen
forall a. IORef a -> IO a
readIORef IORef StdGen
theStdGen
newStdGen :: MonadIO m => m StdGen
newStdGen :: forall (m :: * -> *). MonadIO m => m StdGen
newStdGen = IO StdGen -> m StdGen
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO StdGen -> m StdGen) -> IO StdGen -> m StdGen
forall a b. (a -> b) -> a -> b
$ IORef StdGen -> (StdGen -> (StdGen, StdGen)) -> IO StdGen
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef StdGen
theStdGen StdGen -> (StdGen, StdGen)
forall g. RandomGen g => g -> (g, g)
split
getStdRandom :: MonadIO m => (StdGen -> (a, StdGen)) -> m a
getStdRandom :: forall (m :: * -> *) a. MonadIO m => (StdGen -> (a, StdGen)) -> m a
getStdRandom StdGen -> (a, StdGen)
f = IO a -> m a
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> IO a -> m a
forall a b. (a -> b) -> a -> b
$ IORef StdGen -> (StdGen -> (StdGen, a)) -> IO a
forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef StdGen
theStdGen ((a, StdGen) -> (StdGen, a)
forall {b} {a}. (b, a) -> (a, b)
swap ((a, StdGen) -> (StdGen, a))
-> (StdGen -> (a, StdGen)) -> StdGen -> (StdGen, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StdGen -> (a, StdGen)
f)
where swap :: (b, a) -> (a, b)
swap (b
v, a
g) = (a
g, b
v)
randomRIO :: (Random a, MonadIO m) => (a, a) -> m a
randomRIO :: forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO (a, a)
range = (StdGen -> (a, StdGen)) -> m a
forall (m :: * -> *) a. MonadIO m => (StdGen -> (a, StdGen)) -> m a
getStdRandom ((a, a) -> StdGen -> (a, StdGen)
forall g. RandomGen g => (a, a) -> g -> (a, g)
forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a, a)
range)
randomIO :: (Random a, MonadIO m) => m a
randomIO :: forall a (m :: * -> *). (Random a, MonadIO m) => m a
randomIO = (StdGen -> (a, StdGen)) -> m a
forall (m :: * -> *) a. MonadIO m => (StdGen -> (a, StdGen)) -> m a
getStdRandom StdGen -> (a, StdGen)
forall g. RandomGen g => g -> (a, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random