{-# 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 :: 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
uniformM
{-# INLINE uniform #-}
uniformR :: (RandomGen g, UniformRange a) => (a, a) -> g -> (a, g)
uniformR :: (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
uniformRM (a, a)
r)
{-# INLINE uniformR #-}
genByteString :: RandomGen g => Int -> g -> (ByteString, g)
genByteString :: 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
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
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 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 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 :: (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
`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 :: g -> (Integer, g)
random = (Int -> Integer) -> (Int, g) -> (Integer, g)
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 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 :: (CFloat, CFloat) -> g -> (CFloat, g)
randomR (CFloat, CFloat)
r = (Float, g) -> (CFloat, g)
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 a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR ((CFloat, CFloat) -> (Float, Float)
coerce (CFloat, CFloat)
r :: (Float, Float))
{-# INLINE randomR #-}
random :: g -> (CFloat, g)
random = (Float -> CFloat) -> (Float, g) -> (CFloat, g)
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 a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance Random CDouble where
randomR :: (CDouble, CDouble) -> g -> (CDouble, g)
randomR (CDouble, CDouble)
r = (Double, g) -> (CDouble, g)
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 a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR ((CDouble, CDouble) -> (Double, Double)
coerce (CDouble, CDouble)
r :: (Double, Double))
{-# INLINE randomR #-}
random :: g -> (CDouble, g)
random = (Double -> CDouble) -> (Double, g) -> (CDouble, g)
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 a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
instance Random Char
instance Random Bool
instance Random Double where
randomR :: (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
uniformRM (Double, Double)
r)
{-# INLINE randomR #-}
random :: 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 (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 :: (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
uniformRM (Float, Float)
r)
{-# INLINE randomR #-}
random :: 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 (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 :: m StdGen
initStdGen = IO StdGen -> m StdGen
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 :: ((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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 :: 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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 :: ((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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 :: 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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 :: ((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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 :: 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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 :: ((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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 :: 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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 :: ((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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 :: 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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 :: ((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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (g, g)) -> StateT g Identity g
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state ((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 :: 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 s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (b, g)) -> StateT g Identity b
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (c, g)) -> StateT g Identity c
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (d, g)) -> StateT g Identity d
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (e, g)) -> StateT g Identity e
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (f, g)) -> StateT g Identity f
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state 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 (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (g -> (g, g)) -> StateT g Identity g
forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state g -> (g, g)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random
{-# INLINE random #-}
setStdGen :: MonadIO m => StdGen -> m ()
setStdGen :: StdGen -> m ()
setStdGen = IO () -> m ()
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 :: m StdGen
getStdGen = IO StdGen -> m StdGen
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 :: m StdGen
newStdGen = IO StdGen -> m StdGen
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 :: (StdGen -> (a, StdGen)) -> m a
getStdRandom StdGen -> (a, StdGen)
f = 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 :: (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 a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a, a)
range)
randomIO :: (Random a, MonadIO m) => m a
randomIO :: m a
randomIO = (StdGen -> (a, StdGen)) -> m a
forall (m :: * -> *) a. MonadIO m => (StdGen -> (a, StdGen)) -> m a
getStdRandom StdGen -> (a, StdGen)
forall a g. (Random a, RandomGen g) => g -> (a, g)
random