{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module System.Random.Stateful
(
module System.Random
, StatefulGen(..)
, FrozenGen(..)
, RandomGenM(..)
, withMutableGen
, withMutableGen_
, randomM
, randomRM
, splitGenM
, StateGen(..)
, StateGenM(..)
, runStateGen
, runStateGen_
, runStateGenT
, runStateGenT_
, runStateGenST
, runStateGenST_
, AtomicGen(..)
, AtomicGenM(..)
, newAtomicGenM
, applyAtomicGen
, globalStdGen
, IOGen(..)
, IOGenM(..)
, newIOGenM
, applyIOGen
, STGen(..)
, STGenM(..)
, newSTGenM
, applySTGen
, runSTGen
, runSTGen_
, TGen(..)
, TGenM(..)
, newTGenM
, newTGenMIO
, applyTGen
, Uniform(..)
, uniformListM
, uniformViaFiniteM
, UniformRange(..)
, genShortByteStringIO
, genShortByteStringST
, uniformByteStringM
, uniformDouble01M
, uniformDoublePositive01M
, uniformFloat01M
, uniformFloatPositive01M
, uniformEnumM
, uniformEnumRM
) where
import Control.DeepSeq
import Control.Monad (replicateM)
import Control.Monad.IO.Class
import Control.Monad.ST
import GHC.Conc.Sync (STM, TVar, newTVar, newTVarIO, readTVar, writeTVar)
import Control.Monad.State.Strict (MonadState, state)
import Data.IORef
import Data.STRef
import Foreign.Storable
import System.Random
import System.Random.Internal
class (RandomGen r, StatefulGen g m) => RandomGenM g r m | g -> r where
applyRandomGenM :: (r -> (a, r)) -> g -> m a
splitGenM :: RandomGenM g r m => g -> m r
splitGenM :: forall g r (m :: * -> *). RandomGenM g r m => g -> m r
splitGenM = forall g r (m :: * -> *) a.
RandomGenM g r m =>
(r -> (a, r)) -> g -> m a
applyRandomGenM forall g. RandomGen g => g -> (g, g)
split
instance (RandomGen r, MonadIO m) => RandomGenM (IOGenM r) r m where
applyRandomGenM :: forall a. (r -> (a, r)) -> IOGenM r -> m a
applyRandomGenM = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen
instance (RandomGen r, MonadIO m) => RandomGenM (AtomicGenM r) r m where
applyRandomGenM :: forall a. (r -> (a, r)) -> AtomicGenM r -> m a
applyRandomGenM = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen
instance (RandomGen r, MonadState r m) => RandomGenM (StateGenM r) r m where
applyRandomGenM :: forall a. (r -> (a, r)) -> StateGenM r -> m a
applyRandomGenM r -> (a, r)
f StateGenM r
_ = forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state r -> (a, r)
f
instance RandomGen r => RandomGenM (STGenM r s) r (ST s) where
applyRandomGenM :: forall a. (r -> (a, r)) -> STGenM r s -> ST s a
applyRandomGenM = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen
instance RandomGen r => RandomGenM (TGenM r) r STM where
applyRandomGenM :: forall a. (r -> (a, r)) -> TGenM r -> STM a
applyRandomGenM = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen
withMutableGen :: FrozenGen f m => f -> (MutableGen f m -> m a) -> m (a, f)
withMutableGen :: forall f (m :: * -> *) a.
FrozenGen f m =>
f -> (MutableGen f m -> m a) -> m (a, f)
withMutableGen f
fg MutableGen f m -> m a
action = do
MutableGen f m
g <- forall f (m :: * -> *). FrozenGen f m => f -> m (MutableGen f m)
thawGen f
fg
a
res <- MutableGen f m -> m a
action MutableGen f m
g
f
fg' <- forall f (m :: * -> *). FrozenGen f m => MutableGen f m -> m f
freezeGen MutableGen f m
g
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a
res, f
fg')
withMutableGen_ :: FrozenGen f m => f -> (MutableGen f m -> m a) -> m a
withMutableGen_ :: forall f (m :: * -> *) a.
FrozenGen f m =>
f -> (MutableGen f m -> m a) -> m a
withMutableGen_ f
fg MutableGen f m -> m a
action = forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall f (m :: * -> *) a.
FrozenGen f m =>
f -> (MutableGen f m -> m a) -> m (a, f)
withMutableGen f
fg MutableGen f m -> m a
action
uniformListM :: (StatefulGen g m, Uniform a) => Int -> g -> m [a]
uniformListM :: forall g (m :: * -> *) a.
(StatefulGen g m, Uniform a) =>
Int -> g -> m [a]
uniformListM Int
n g
gen = forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n (forall a g (m :: * -> *). (Uniform a, StatefulGen g m) => g -> m a
uniformM g
gen)
randomM :: (RandomGenM g r m, Random a) => g -> m a
randomM :: forall g r (m :: * -> *) a.
(RandomGenM g r m, Random a) =>
g -> m a
randomM = forall g r (m :: * -> *) a.
RandomGenM g r m =>
(r -> (a, r)) -> g -> m a
applyRandomGenM forall a g. (Random a, RandomGen g) => g -> (a, g)
random
randomRM :: (RandomGenM g r m, Random a) => (a, a) -> g -> m a
randomRM :: forall g r (m :: * -> *) a.
(RandomGenM g r m, Random a) =>
(a, a) -> g -> m a
randomRM (a, a)
r = forall g r (m :: * -> *) a.
RandomGenM g r m =>
(r -> (a, r)) -> g -> m a
applyRandomGenM (forall a g. (Random a, RandomGen g) => (a, a) -> g -> (a, g)
randomR (a, a)
r)
newtype AtomicGenM g = AtomicGenM { forall g. AtomicGenM g -> IORef g
unAtomicGenM :: IORef g}
newtype AtomicGen g = AtomicGen { forall g. AtomicGen g -> g
unAtomicGen :: g}
deriving (AtomicGen g -> AtomicGen g -> Bool
forall g. Eq g => AtomicGen g -> AtomicGen g -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AtomicGen g -> AtomicGen g -> Bool
$c/= :: forall g. Eq g => AtomicGen g -> AtomicGen g -> Bool
== :: AtomicGen g -> AtomicGen g -> Bool
$c== :: forall g. Eq g => AtomicGen g -> AtomicGen g -> Bool
Eq, AtomicGen g -> AtomicGen g -> Bool
AtomicGen g -> AtomicGen g -> Ordering
AtomicGen g -> AtomicGen g -> AtomicGen g
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {g}. Ord g => Eq (AtomicGen g)
forall g. Ord g => AtomicGen g -> AtomicGen g -> Bool
forall g. Ord g => AtomicGen g -> AtomicGen g -> Ordering
forall g. Ord g => AtomicGen g -> AtomicGen g -> AtomicGen g
min :: AtomicGen g -> AtomicGen g -> AtomicGen g
$cmin :: forall g. Ord g => AtomicGen g -> AtomicGen g -> AtomicGen g
max :: AtomicGen g -> AtomicGen g -> AtomicGen g
$cmax :: forall g. Ord g => AtomicGen g -> AtomicGen g -> AtomicGen g
>= :: AtomicGen g -> AtomicGen g -> Bool
$c>= :: forall g. Ord g => AtomicGen g -> AtomicGen g -> Bool
> :: AtomicGen g -> AtomicGen g -> Bool
$c> :: forall g. Ord g => AtomicGen g -> AtomicGen g -> Bool
<= :: AtomicGen g -> AtomicGen g -> Bool
$c<= :: forall g. Ord g => AtomicGen g -> AtomicGen g -> Bool
< :: AtomicGen g -> AtomicGen g -> Bool
$c< :: forall g. Ord g => AtomicGen g -> AtomicGen g -> Bool
compare :: AtomicGen g -> AtomicGen g -> Ordering
$ccompare :: forall g. Ord g => AtomicGen g -> AtomicGen g -> Ordering
Ord, Int -> AtomicGen g -> ShowS
forall g. Show g => Int -> AtomicGen g -> ShowS
forall g. Show g => [AtomicGen g] -> ShowS
forall g. Show g => AtomicGen g -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AtomicGen g] -> ShowS
$cshowList :: forall g. Show g => [AtomicGen g] -> ShowS
show :: AtomicGen g -> String
$cshow :: forall g. Show g => AtomicGen g -> String
showsPrec :: Int -> AtomicGen g -> ShowS
$cshowsPrec :: forall g. Show g => Int -> AtomicGen g -> ShowS
Show, Int -> AtomicGen g -> (ShortByteString, AtomicGen g)
Word32 -> AtomicGen g -> (Word32, AtomicGen g)
Word64 -> AtomicGen g -> (Word64, AtomicGen g)
AtomicGen g -> (Int, Int)
AtomicGen g -> (Int, AtomicGen g)
AtomicGen g -> (Word8, AtomicGen g)
AtomicGen g -> (Word16, AtomicGen g)
AtomicGen g -> (Word32, AtomicGen g)
AtomicGen g -> (Word64, AtomicGen g)
AtomicGen g -> (AtomicGen g, AtomicGen g)
forall g.
RandomGen g =>
Int -> AtomicGen g -> (ShortByteString, AtomicGen g)
forall g.
RandomGen g =>
Word32 -> AtomicGen g -> (Word32, AtomicGen g)
forall g.
RandomGen g =>
Word64 -> AtomicGen g -> (Word64, AtomicGen g)
forall g. RandomGen g => AtomicGen g -> (Int, Int)
forall g. RandomGen g => AtomicGen g -> (Int, AtomicGen g)
forall g. RandomGen g => AtomicGen g -> (Word8, AtomicGen g)
forall g. RandomGen g => AtomicGen g -> (Word16, AtomicGen g)
forall g. RandomGen g => AtomicGen g -> (Word32, AtomicGen g)
forall g. RandomGen g => AtomicGen g -> (Word64, AtomicGen g)
forall g. RandomGen g => AtomicGen g -> (AtomicGen g, AtomicGen g)
forall g.
(g -> (Int, g))
-> (g -> (Word8, g))
-> (g -> (Word16, g))
-> (g -> (Word32, g))
-> (g -> (Word64, g))
-> (Word32 -> g -> (Word32, g))
-> (Word64 -> g -> (Word64, g))
-> (Int -> g -> (ShortByteString, g))
-> (g -> (Int, Int))
-> (g -> (g, g))
-> RandomGen g
split :: AtomicGen g -> (AtomicGen g, AtomicGen g)
$csplit :: forall g. RandomGen g => AtomicGen g -> (AtomicGen g, AtomicGen g)
genRange :: AtomicGen g -> (Int, Int)
$cgenRange :: forall g. RandomGen g => AtomicGen g -> (Int, Int)
genShortByteString :: Int -> AtomicGen g -> (ShortByteString, AtomicGen g)
$cgenShortByteString :: forall g.
RandomGen g =>
Int -> AtomicGen g -> (ShortByteString, AtomicGen g)
genWord64R :: Word64 -> AtomicGen g -> (Word64, AtomicGen g)
$cgenWord64R :: forall g.
RandomGen g =>
Word64 -> AtomicGen g -> (Word64, AtomicGen g)
genWord32R :: Word32 -> AtomicGen g -> (Word32, AtomicGen g)
$cgenWord32R :: forall g.
RandomGen g =>
Word32 -> AtomicGen g -> (Word32, AtomicGen g)
genWord64 :: AtomicGen g -> (Word64, AtomicGen g)
$cgenWord64 :: forall g. RandomGen g => AtomicGen g -> (Word64, AtomicGen g)
genWord32 :: AtomicGen g -> (Word32, AtomicGen g)
$cgenWord32 :: forall g. RandomGen g => AtomicGen g -> (Word32, AtomicGen g)
genWord16 :: AtomicGen g -> (Word16, AtomicGen g)
$cgenWord16 :: forall g. RandomGen g => AtomicGen g -> (Word16, AtomicGen g)
genWord8 :: AtomicGen g -> (Word8, AtomicGen g)
$cgenWord8 :: forall g. RandomGen g => AtomicGen g -> (Word8, AtomicGen g)
next :: AtomicGen g -> (Int, AtomicGen g)
$cnext :: forall g. RandomGen g => AtomicGen g -> (Int, AtomicGen g)
RandomGen, Ptr (AtomicGen g) -> IO (AtomicGen g)
Ptr (AtomicGen g) -> Int -> IO (AtomicGen g)
Ptr (AtomicGen g) -> Int -> AtomicGen g -> IO ()
Ptr (AtomicGen g) -> AtomicGen g -> IO ()
AtomicGen g -> Int
forall b. Ptr b -> Int -> IO (AtomicGen g)
forall b. Ptr b -> Int -> AtomicGen g -> IO ()
forall g. Storable g => Ptr (AtomicGen g) -> IO (AtomicGen g)
forall g.
Storable g =>
Ptr (AtomicGen g) -> Int -> IO (AtomicGen g)
forall g.
Storable g =>
Ptr (AtomicGen g) -> Int -> AtomicGen g -> IO ()
forall g. Storable g => Ptr (AtomicGen g) -> AtomicGen g -> IO ()
forall g. Storable g => AtomicGen g -> Int
forall g b. Storable g => Ptr b -> Int -> IO (AtomicGen g)
forall g b. Storable g => Ptr b -> Int -> AtomicGen g -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
poke :: Ptr (AtomicGen g) -> AtomicGen g -> IO ()
$cpoke :: forall g. Storable g => Ptr (AtomicGen g) -> AtomicGen g -> IO ()
peek :: Ptr (AtomicGen g) -> IO (AtomicGen g)
$cpeek :: forall g. Storable g => Ptr (AtomicGen g) -> IO (AtomicGen g)
pokeByteOff :: forall b. Ptr b -> Int -> AtomicGen g -> IO ()
$cpokeByteOff :: forall g b. Storable g => Ptr b -> Int -> AtomicGen g -> IO ()
peekByteOff :: forall b. Ptr b -> Int -> IO (AtomicGen g)
$cpeekByteOff :: forall g b. Storable g => Ptr b -> Int -> IO (AtomicGen g)
pokeElemOff :: Ptr (AtomicGen g) -> Int -> AtomicGen g -> IO ()
$cpokeElemOff :: forall g.
Storable g =>
Ptr (AtomicGen g) -> Int -> AtomicGen g -> IO ()
peekElemOff :: Ptr (AtomicGen g) -> Int -> IO (AtomicGen g)
$cpeekElemOff :: forall g.
Storable g =>
Ptr (AtomicGen g) -> Int -> IO (AtomicGen g)
alignment :: AtomicGen g -> Int
$calignment :: forall g. Storable g => AtomicGen g -> Int
sizeOf :: AtomicGen g -> Int
$csizeOf :: forall g. Storable g => AtomicGen g -> Int
Storable, AtomicGen g -> ()
forall g. NFData g => AtomicGen g -> ()
forall a. (a -> ()) -> NFData a
rnf :: AtomicGen g -> ()
$crnf :: forall g. NFData g => AtomicGen g -> ()
NFData)
newAtomicGenM :: MonadIO m => g -> m (AtomicGenM g)
newAtomicGenM :: forall (m :: * -> *) g. MonadIO m => g -> m (AtomicGenM g)
newAtomicGenM = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g. IORef g -> AtomicGenM g
AtomicGenM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> IO (IORef a)
newIORef
globalStdGen :: AtomicGenM StdGen
globalStdGen :: AtomicGenM StdGen
globalStdGen = forall g. IORef g -> AtomicGenM g
AtomicGenM IORef StdGen
theStdGen
instance (RandomGen g, MonadIO m) => StatefulGen (AtomicGenM g) m where
uniformWord32R :: Word32 -> AtomicGenM g -> m Word32
uniformWord32R Word32
r = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen (forall g. RandomGen g => Word32 -> g -> (Word32, g)
genWord32R Word32
r)
{-# INLINE uniformWord32R #-}
uniformWord64R :: Word64 -> AtomicGenM g -> m Word64
uniformWord64R Word64
r = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen (forall g. RandomGen g => Word64 -> g -> (Word64, g)
genWord64R Word64
r)
{-# INLINE uniformWord64R #-}
uniformWord8 :: AtomicGenM g -> m Word8
uniformWord8 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen forall g. RandomGen g => g -> (Word8, g)
genWord8
{-# INLINE uniformWord8 #-}
uniformWord16 :: AtomicGenM g -> m Word16
uniformWord16 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen forall g. RandomGen g => g -> (Word16, g)
genWord16
{-# INLINE uniformWord16 #-}
uniformWord32 :: AtomicGenM g -> m Word32
uniformWord32 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen forall g. RandomGen g => g -> (Word32, g)
genWord32
{-# INLINE uniformWord32 #-}
uniformWord64 :: AtomicGenM g -> m Word64
uniformWord64 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen forall g. RandomGen g => g -> (Word64, g)
genWord64
{-# INLINE uniformWord64 #-}
uniformShortByteString :: Int -> AtomicGenM g -> m ShortByteString
uniformShortByteString Int
n = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen (forall g. RandomGen g => Int -> g -> (ShortByteString, g)
genShortByteString Int
n)
instance (RandomGen g, MonadIO m) => FrozenGen (AtomicGen g) m where
type MutableGen (AtomicGen g) m = AtomicGenM g
freezeGen :: MutableGen (AtomicGen g) m -> m (AtomicGen g)
freezeGen = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g. g -> AtomicGen g
AtomicGen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IORef a -> IO a
readIORef forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g. AtomicGenM g -> IORef g
unAtomicGenM
thawGen :: AtomicGen g -> m (MutableGen (AtomicGen g) m)
thawGen (AtomicGen g
g) = forall (m :: * -> *) g. MonadIO m => g -> m (AtomicGenM g)
newAtomicGenM g
g
applyAtomicGen :: MonadIO m => (g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen :: forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> AtomicGenM g -> m a
applyAtomicGen g -> (a, g)
op (AtomicGenM IORef g
gVar) =
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall a b. IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef' IORef g
gVar forall a b. (a -> b) -> a -> b
$ \g
g ->
case g -> (a, g)
op g
g of
(a
a, g
g') -> (g
g', a
a)
{-# INLINE applyAtomicGen #-}
newtype IOGenM g = IOGenM { forall g. IOGenM g -> IORef g
unIOGenM :: IORef g }
newtype IOGen g = IOGen { forall g. IOGen g -> g
unIOGen :: g }
deriving (IOGen g -> IOGen g -> Bool
forall g. Eq g => IOGen g -> IOGen g -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IOGen g -> IOGen g -> Bool
$c/= :: forall g. Eq g => IOGen g -> IOGen g -> Bool
== :: IOGen g -> IOGen g -> Bool
$c== :: forall g. Eq g => IOGen g -> IOGen g -> Bool
Eq, IOGen g -> IOGen g -> Bool
IOGen g -> IOGen g -> Ordering
IOGen g -> IOGen g -> IOGen g
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {g}. Ord g => Eq (IOGen g)
forall g. Ord g => IOGen g -> IOGen g -> Bool
forall g. Ord g => IOGen g -> IOGen g -> Ordering
forall g. Ord g => IOGen g -> IOGen g -> IOGen g
min :: IOGen g -> IOGen g -> IOGen g
$cmin :: forall g. Ord g => IOGen g -> IOGen g -> IOGen g
max :: IOGen g -> IOGen g -> IOGen g
$cmax :: forall g. Ord g => IOGen g -> IOGen g -> IOGen g
>= :: IOGen g -> IOGen g -> Bool
$c>= :: forall g. Ord g => IOGen g -> IOGen g -> Bool
> :: IOGen g -> IOGen g -> Bool
$c> :: forall g. Ord g => IOGen g -> IOGen g -> Bool
<= :: IOGen g -> IOGen g -> Bool
$c<= :: forall g. Ord g => IOGen g -> IOGen g -> Bool
< :: IOGen g -> IOGen g -> Bool
$c< :: forall g. Ord g => IOGen g -> IOGen g -> Bool
compare :: IOGen g -> IOGen g -> Ordering
$ccompare :: forall g. Ord g => IOGen g -> IOGen g -> Ordering
Ord, Int -> IOGen g -> ShowS
forall g. Show g => Int -> IOGen g -> ShowS
forall g. Show g => [IOGen g] -> ShowS
forall g. Show g => IOGen g -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IOGen g] -> ShowS
$cshowList :: forall g. Show g => [IOGen g] -> ShowS
show :: IOGen g -> String
$cshow :: forall g. Show g => IOGen g -> String
showsPrec :: Int -> IOGen g -> ShowS
$cshowsPrec :: forall g. Show g => Int -> IOGen g -> ShowS
Show, Int -> IOGen g -> (ShortByteString, IOGen g)
Word32 -> IOGen g -> (Word32, IOGen g)
Word64 -> IOGen g -> (Word64, IOGen g)
IOGen g -> (Int, Int)
IOGen g -> (Int, IOGen g)
IOGen g -> (Word8, IOGen g)
IOGen g -> (Word16, IOGen g)
IOGen g -> (Word32, IOGen g)
IOGen g -> (Word64, IOGen g)
IOGen g -> (IOGen g, IOGen g)
forall g.
RandomGen g =>
Int -> IOGen g -> (ShortByteString, IOGen g)
forall g. RandomGen g => Word32 -> IOGen g -> (Word32, IOGen g)
forall g. RandomGen g => Word64 -> IOGen g -> (Word64, IOGen g)
forall g. RandomGen g => IOGen g -> (Int, Int)
forall g. RandomGen g => IOGen g -> (Int, IOGen g)
forall g. RandomGen g => IOGen g -> (Word8, IOGen g)
forall g. RandomGen g => IOGen g -> (Word16, IOGen g)
forall g. RandomGen g => IOGen g -> (Word32, IOGen g)
forall g. RandomGen g => IOGen g -> (Word64, IOGen g)
forall g. RandomGen g => IOGen g -> (IOGen g, IOGen g)
forall g.
(g -> (Int, g))
-> (g -> (Word8, g))
-> (g -> (Word16, g))
-> (g -> (Word32, g))
-> (g -> (Word64, g))
-> (Word32 -> g -> (Word32, g))
-> (Word64 -> g -> (Word64, g))
-> (Int -> g -> (ShortByteString, g))
-> (g -> (Int, Int))
-> (g -> (g, g))
-> RandomGen g
split :: IOGen g -> (IOGen g, IOGen g)
$csplit :: forall g. RandomGen g => IOGen g -> (IOGen g, IOGen g)
genRange :: IOGen g -> (Int, Int)
$cgenRange :: forall g. RandomGen g => IOGen g -> (Int, Int)
genShortByteString :: Int -> IOGen g -> (ShortByteString, IOGen g)
$cgenShortByteString :: forall g.
RandomGen g =>
Int -> IOGen g -> (ShortByteString, IOGen g)
genWord64R :: Word64 -> IOGen g -> (Word64, IOGen g)
$cgenWord64R :: forall g. RandomGen g => Word64 -> IOGen g -> (Word64, IOGen g)
genWord32R :: Word32 -> IOGen g -> (Word32, IOGen g)
$cgenWord32R :: forall g. RandomGen g => Word32 -> IOGen g -> (Word32, IOGen g)
genWord64 :: IOGen g -> (Word64, IOGen g)
$cgenWord64 :: forall g. RandomGen g => IOGen g -> (Word64, IOGen g)
genWord32 :: IOGen g -> (Word32, IOGen g)
$cgenWord32 :: forall g. RandomGen g => IOGen g -> (Word32, IOGen g)
genWord16 :: IOGen g -> (Word16, IOGen g)
$cgenWord16 :: forall g. RandomGen g => IOGen g -> (Word16, IOGen g)
genWord8 :: IOGen g -> (Word8, IOGen g)
$cgenWord8 :: forall g. RandomGen g => IOGen g -> (Word8, IOGen g)
next :: IOGen g -> (Int, IOGen g)
$cnext :: forall g. RandomGen g => IOGen g -> (Int, IOGen g)
RandomGen, Ptr (IOGen g) -> IO (IOGen g)
Ptr (IOGen g) -> Int -> IO (IOGen g)
Ptr (IOGen g) -> Int -> IOGen g -> IO ()
Ptr (IOGen g) -> IOGen g -> IO ()
IOGen g -> Int
forall b. Ptr b -> Int -> IO (IOGen g)
forall b. Ptr b -> Int -> IOGen g -> IO ()
forall g. Storable g => Ptr (IOGen g) -> IO (IOGen g)
forall g. Storable g => Ptr (IOGen g) -> Int -> IO (IOGen g)
forall g. Storable g => Ptr (IOGen g) -> Int -> IOGen g -> IO ()
forall g. Storable g => Ptr (IOGen g) -> IOGen g -> IO ()
forall g. Storable g => IOGen g -> Int
forall g b. Storable g => Ptr b -> Int -> IO (IOGen g)
forall g b. Storable g => Ptr b -> Int -> IOGen g -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
poke :: Ptr (IOGen g) -> IOGen g -> IO ()
$cpoke :: forall g. Storable g => Ptr (IOGen g) -> IOGen g -> IO ()
peek :: Ptr (IOGen g) -> IO (IOGen g)
$cpeek :: forall g. Storable g => Ptr (IOGen g) -> IO (IOGen g)
pokeByteOff :: forall b. Ptr b -> Int -> IOGen g -> IO ()
$cpokeByteOff :: forall g b. Storable g => Ptr b -> Int -> IOGen g -> IO ()
peekByteOff :: forall b. Ptr b -> Int -> IO (IOGen g)
$cpeekByteOff :: forall g b. Storable g => Ptr b -> Int -> IO (IOGen g)
pokeElemOff :: Ptr (IOGen g) -> Int -> IOGen g -> IO ()
$cpokeElemOff :: forall g. Storable g => Ptr (IOGen g) -> Int -> IOGen g -> IO ()
peekElemOff :: Ptr (IOGen g) -> Int -> IO (IOGen g)
$cpeekElemOff :: forall g. Storable g => Ptr (IOGen g) -> Int -> IO (IOGen g)
alignment :: IOGen g -> Int
$calignment :: forall g. Storable g => IOGen g -> Int
sizeOf :: IOGen g -> Int
$csizeOf :: forall g. Storable g => IOGen g -> Int
Storable, IOGen g -> ()
forall g. NFData g => IOGen g -> ()
forall a. (a -> ()) -> NFData a
rnf :: IOGen g -> ()
$crnf :: forall g. NFData g => IOGen g -> ()
NFData)
newIOGenM :: MonadIO m => g -> m (IOGenM g)
newIOGenM :: forall (m :: * -> *) g. MonadIO m => g -> m (IOGenM g)
newIOGenM = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g. IORef g -> IOGenM g
IOGenM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> IO (IORef a)
newIORef
instance (RandomGen g, MonadIO m) => StatefulGen (IOGenM g) m where
uniformWord32R :: Word32 -> IOGenM g -> m Word32
uniformWord32R Word32
r = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen (forall g. RandomGen g => Word32 -> g -> (Word32, g)
genWord32R Word32
r)
{-# INLINE uniformWord32R #-}
uniformWord64R :: Word64 -> IOGenM g -> m Word64
uniformWord64R Word64
r = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen (forall g. RandomGen g => Word64 -> g -> (Word64, g)
genWord64R Word64
r)
{-# INLINE uniformWord64R #-}
uniformWord8 :: IOGenM g -> m Word8
uniformWord8 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen forall g. RandomGen g => g -> (Word8, g)
genWord8
{-# INLINE uniformWord8 #-}
uniformWord16 :: IOGenM g -> m Word16
uniformWord16 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen forall g. RandomGen g => g -> (Word16, g)
genWord16
{-# INLINE uniformWord16 #-}
uniformWord32 :: IOGenM g -> m Word32
uniformWord32 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen forall g. RandomGen g => g -> (Word32, g)
genWord32
{-# INLINE uniformWord32 #-}
uniformWord64 :: IOGenM g -> m Word64
uniformWord64 = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen forall g. RandomGen g => g -> (Word64, g)
genWord64
{-# INLINE uniformWord64 #-}
uniformShortByteString :: Int -> IOGenM g -> m ShortByteString
uniformShortByteString Int
n = forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen (forall g. RandomGen g => Int -> g -> (ShortByteString, g)
genShortByteString Int
n)
instance (RandomGen g, MonadIO m) => FrozenGen (IOGen g) m where
type MutableGen (IOGen g) m = IOGenM g
freezeGen :: MutableGen (IOGen g) m -> m (IOGen g)
freezeGen = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g. g -> IOGen g
IOGen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IORef a -> IO a
readIORef forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g. IOGenM g -> IORef g
unIOGenM
thawGen :: IOGen g -> m (MutableGen (IOGen g) m)
thawGen (IOGen g
g) = forall (m :: * -> *) g. MonadIO m => g -> m (IOGenM g)
newIOGenM g
g
applyIOGen :: MonadIO m => (g -> (a, g)) -> IOGenM g -> m a
applyIOGen :: forall (m :: * -> *) g a.
MonadIO m =>
(g -> (a, g)) -> IOGenM g -> m a
applyIOGen g -> (a, g)
f (IOGenM IORef g
ref) = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ do
g
g <- forall a. IORef a -> IO a
readIORef IORef g
ref
case g -> (a, g)
f g
g of
(!a
a, !g
g') -> a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall a. IORef a -> a -> IO ()
writeIORef IORef g
ref g
g'
{-# INLINE applyIOGen #-}
newtype STGenM g s = STGenM { forall g s. STGenM g s -> STRef s g
unSTGenM :: STRef s g }
newtype STGen g = STGen { forall g. STGen g -> g
unSTGen :: g }
deriving (STGen g -> STGen g -> Bool
forall g. Eq g => STGen g -> STGen g -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: STGen g -> STGen g -> Bool
$c/= :: forall g. Eq g => STGen g -> STGen g -> Bool
== :: STGen g -> STGen g -> Bool
$c== :: forall g. Eq g => STGen g -> STGen g -> Bool
Eq, STGen g -> STGen g -> Bool
STGen g -> STGen g -> Ordering
STGen g -> STGen g -> STGen g
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {g}. Ord g => Eq (STGen g)
forall g. Ord g => STGen g -> STGen g -> Bool
forall g. Ord g => STGen g -> STGen g -> Ordering
forall g. Ord g => STGen g -> STGen g -> STGen g
min :: STGen g -> STGen g -> STGen g
$cmin :: forall g. Ord g => STGen g -> STGen g -> STGen g
max :: STGen g -> STGen g -> STGen g
$cmax :: forall g. Ord g => STGen g -> STGen g -> STGen g
>= :: STGen g -> STGen g -> Bool
$c>= :: forall g. Ord g => STGen g -> STGen g -> Bool
> :: STGen g -> STGen g -> Bool
$c> :: forall g. Ord g => STGen g -> STGen g -> Bool
<= :: STGen g -> STGen g -> Bool
$c<= :: forall g. Ord g => STGen g -> STGen g -> Bool
< :: STGen g -> STGen g -> Bool
$c< :: forall g. Ord g => STGen g -> STGen g -> Bool
compare :: STGen g -> STGen g -> Ordering
$ccompare :: forall g. Ord g => STGen g -> STGen g -> Ordering
Ord, Int -> STGen g -> ShowS
forall g. Show g => Int -> STGen g -> ShowS
forall g. Show g => [STGen g] -> ShowS
forall g. Show g => STGen g -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [STGen g] -> ShowS
$cshowList :: forall g. Show g => [STGen g] -> ShowS
show :: STGen g -> String
$cshow :: forall g. Show g => STGen g -> String
showsPrec :: Int -> STGen g -> ShowS
$cshowsPrec :: forall g. Show g => Int -> STGen g -> ShowS
Show, Int -> STGen g -> (ShortByteString, STGen g)
Word32 -> STGen g -> (Word32, STGen g)
Word64 -> STGen g -> (Word64, STGen g)
STGen g -> (Int, Int)
STGen g -> (Int, STGen g)
STGen g -> (Word8, STGen g)
STGen g -> (Word16, STGen g)
STGen g -> (Word32, STGen g)
STGen g -> (Word64, STGen g)
STGen g -> (STGen g, STGen g)
forall g.
RandomGen g =>
Int -> STGen g -> (ShortByteString, STGen g)
forall g. RandomGen g => Word32 -> STGen g -> (Word32, STGen g)
forall g. RandomGen g => Word64 -> STGen g -> (Word64, STGen g)
forall g. RandomGen g => STGen g -> (Int, Int)
forall g. RandomGen g => STGen g -> (Int, STGen g)
forall g. RandomGen g => STGen g -> (Word8, STGen g)
forall g. RandomGen g => STGen g -> (Word16, STGen g)
forall g. RandomGen g => STGen g -> (Word32, STGen g)
forall g. RandomGen g => STGen g -> (Word64, STGen g)
forall g. RandomGen g => STGen g -> (STGen g, STGen g)
forall g.
(g -> (Int, g))
-> (g -> (Word8, g))
-> (g -> (Word16, g))
-> (g -> (Word32, g))
-> (g -> (Word64, g))
-> (Word32 -> g -> (Word32, g))
-> (Word64 -> g -> (Word64, g))
-> (Int -> g -> (ShortByteString, g))
-> (g -> (Int, Int))
-> (g -> (g, g))
-> RandomGen g
split :: STGen g -> (STGen g, STGen g)
$csplit :: forall g. RandomGen g => STGen g -> (STGen g, STGen g)
genRange :: STGen g -> (Int, Int)
$cgenRange :: forall g. RandomGen g => STGen g -> (Int, Int)
genShortByteString :: Int -> STGen g -> (ShortByteString, STGen g)
$cgenShortByteString :: forall g.
RandomGen g =>
Int -> STGen g -> (ShortByteString, STGen g)
genWord64R :: Word64 -> STGen g -> (Word64, STGen g)
$cgenWord64R :: forall g. RandomGen g => Word64 -> STGen g -> (Word64, STGen g)
genWord32R :: Word32 -> STGen g -> (Word32, STGen g)
$cgenWord32R :: forall g. RandomGen g => Word32 -> STGen g -> (Word32, STGen g)
genWord64 :: STGen g -> (Word64, STGen g)
$cgenWord64 :: forall g. RandomGen g => STGen g -> (Word64, STGen g)
genWord32 :: STGen g -> (Word32, STGen g)
$cgenWord32 :: forall g. RandomGen g => STGen g -> (Word32, STGen g)
genWord16 :: STGen g -> (Word16, STGen g)
$cgenWord16 :: forall g. RandomGen g => STGen g -> (Word16, STGen g)
genWord8 :: STGen g -> (Word8, STGen g)
$cgenWord8 :: forall g. RandomGen g => STGen g -> (Word8, STGen g)
next :: STGen g -> (Int, STGen g)
$cnext :: forall g. RandomGen g => STGen g -> (Int, STGen g)
RandomGen, Ptr (STGen g) -> IO (STGen g)
Ptr (STGen g) -> Int -> IO (STGen g)
Ptr (STGen g) -> Int -> STGen g -> IO ()
Ptr (STGen g) -> STGen g -> IO ()
STGen g -> Int
forall b. Ptr b -> Int -> IO (STGen g)
forall b. Ptr b -> Int -> STGen g -> IO ()
forall g. Storable g => Ptr (STGen g) -> IO (STGen g)
forall g. Storable g => Ptr (STGen g) -> Int -> IO (STGen g)
forall g. Storable g => Ptr (STGen g) -> Int -> STGen g -> IO ()
forall g. Storable g => Ptr (STGen g) -> STGen g -> IO ()
forall g. Storable g => STGen g -> Int
forall g b. Storable g => Ptr b -> Int -> IO (STGen g)
forall g b. Storable g => Ptr b -> Int -> STGen g -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
poke :: Ptr (STGen g) -> STGen g -> IO ()
$cpoke :: forall g. Storable g => Ptr (STGen g) -> STGen g -> IO ()
peek :: Ptr (STGen g) -> IO (STGen g)
$cpeek :: forall g. Storable g => Ptr (STGen g) -> IO (STGen g)
pokeByteOff :: forall b. Ptr b -> Int -> STGen g -> IO ()
$cpokeByteOff :: forall g b. Storable g => Ptr b -> Int -> STGen g -> IO ()
peekByteOff :: forall b. Ptr b -> Int -> IO (STGen g)
$cpeekByteOff :: forall g b. Storable g => Ptr b -> Int -> IO (STGen g)
pokeElemOff :: Ptr (STGen g) -> Int -> STGen g -> IO ()
$cpokeElemOff :: forall g. Storable g => Ptr (STGen g) -> Int -> STGen g -> IO ()
peekElemOff :: Ptr (STGen g) -> Int -> IO (STGen g)
$cpeekElemOff :: forall g. Storable g => Ptr (STGen g) -> Int -> IO (STGen g)
alignment :: STGen g -> Int
$calignment :: forall g. Storable g => STGen g -> Int
sizeOf :: STGen g -> Int
$csizeOf :: forall g. Storable g => STGen g -> Int
Storable, STGen g -> ()
forall g. NFData g => STGen g -> ()
forall a. (a -> ()) -> NFData a
rnf :: STGen g -> ()
$crnf :: forall g. NFData g => STGen g -> ()
NFData)
newSTGenM :: g -> ST s (STGenM g s)
newSTGenM :: forall g s. g -> ST s (STGenM g s)
newSTGenM = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g s. STRef s g -> STGenM g s
STGenM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a s. a -> ST s (STRef s a)
newSTRef
instance RandomGen g => StatefulGen (STGenM g s) (ST s) where
uniformWord32R :: Word32 -> STGenM g s -> ST s Word32
uniformWord32R Word32
r = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen (forall g. RandomGen g => Word32 -> g -> (Word32, g)
genWord32R Word32
r)
{-# INLINE uniformWord32R #-}
uniformWord64R :: Word64 -> STGenM g s -> ST s Word64
uniformWord64R Word64
r = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen (forall g. RandomGen g => Word64 -> g -> (Word64, g)
genWord64R Word64
r)
{-# INLINE uniformWord64R #-}
uniformWord8 :: STGenM g s -> ST s Word8
uniformWord8 = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen forall g. RandomGen g => g -> (Word8, g)
genWord8
{-# INLINE uniformWord8 #-}
uniformWord16 :: STGenM g s -> ST s Word16
uniformWord16 = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen forall g. RandomGen g => g -> (Word16, g)
genWord16
{-# INLINE uniformWord16 #-}
uniformWord32 :: STGenM g s -> ST s Word32
uniformWord32 = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen forall g. RandomGen g => g -> (Word32, g)
genWord32
{-# INLINE uniformWord32 #-}
uniformWord64 :: STGenM g s -> ST s Word64
uniformWord64 = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen forall g. RandomGen g => g -> (Word64, g)
genWord64
{-# INLINE uniformWord64 #-}
uniformShortByteString :: Int -> STGenM g s -> ST s ShortByteString
uniformShortByteString Int
n = forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen (forall g. RandomGen g => Int -> g -> (ShortByteString, g)
genShortByteString Int
n)
instance RandomGen g => FrozenGen (STGen g) (ST s) where
type MutableGen (STGen g) (ST s) = STGenM g s
freezeGen :: MutableGen (STGen g) (ST s) -> ST s (STGen g)
freezeGen = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g. g -> STGen g
STGen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. STRef s a -> ST s a
readSTRef forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g s. STGenM g s -> STRef s g
unSTGenM
thawGen :: STGen g -> ST s (MutableGen (STGen g) (ST s))
thawGen (STGen g
g) = forall g s. g -> ST s (STGenM g s)
newSTGenM g
g
applySTGen :: (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen :: forall g a s. (g -> (a, g)) -> STGenM g s -> ST s a
applySTGen g -> (a, g)
f (STGenM STRef s g
ref) = do
g
g <- forall s a. STRef s a -> ST s a
readSTRef STRef s g
ref
case g -> (a, g)
f g
g of
(!a
a, !g
g') -> a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s a. STRef s a -> a -> ST s ()
writeSTRef STRef s g
ref g
g'
{-# INLINE applySTGen #-}
runSTGen :: RandomGen g => g -> (forall s . STGenM g s -> ST s a) -> (a, g)
runSTGen :: forall g a.
RandomGen g =>
g -> (forall s. STGenM g s -> ST s a) -> (a, g)
runSTGen g
g forall s. STGenM g s -> ST s a
action = forall g. STGen g -> g
unSTGen forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. (forall s. ST s a) -> a
runST (forall f (m :: * -> *) a.
FrozenGen f m =>
f -> (MutableGen f m -> m a) -> m (a, f)
withMutableGen (forall g. g -> STGen g
STGen g
g) forall s. STGenM g s -> ST s a
action)
runSTGen_ :: RandomGen g => g -> (forall s . STGenM g s -> ST s a) -> a
runSTGen_ :: forall g a.
RandomGen g =>
g -> (forall s. STGenM g s -> ST s a) -> a
runSTGen_ g
g forall s. STGenM g s -> ST s a
action = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall g a.
RandomGen g =>
g -> (forall s. STGenM g s -> ST s a) -> (a, g)
runSTGen g
g forall s. STGenM g s -> ST s a
action
newtype TGenM g = TGenM { forall g. TGenM g -> TVar g
unTGenM :: TVar g }
newtype TGen g = TGen { forall g. TGen g -> g
unTGen :: g }
deriving (TGen g -> TGen g -> Bool
forall g. Eq g => TGen g -> TGen g -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TGen g -> TGen g -> Bool
$c/= :: forall g. Eq g => TGen g -> TGen g -> Bool
== :: TGen g -> TGen g -> Bool
$c== :: forall g. Eq g => TGen g -> TGen g -> Bool
Eq, TGen g -> TGen g -> Bool
TGen g -> TGen g -> Ordering
TGen g -> TGen g -> TGen g
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {g}. Ord g => Eq (TGen g)
forall g. Ord g => TGen g -> TGen g -> Bool
forall g. Ord g => TGen g -> TGen g -> Ordering
forall g. Ord g => TGen g -> TGen g -> TGen g
min :: TGen g -> TGen g -> TGen g
$cmin :: forall g. Ord g => TGen g -> TGen g -> TGen g
max :: TGen g -> TGen g -> TGen g
$cmax :: forall g. Ord g => TGen g -> TGen g -> TGen g
>= :: TGen g -> TGen g -> Bool
$c>= :: forall g. Ord g => TGen g -> TGen g -> Bool
> :: TGen g -> TGen g -> Bool
$c> :: forall g. Ord g => TGen g -> TGen g -> Bool
<= :: TGen g -> TGen g -> Bool
$c<= :: forall g. Ord g => TGen g -> TGen g -> Bool
< :: TGen g -> TGen g -> Bool
$c< :: forall g. Ord g => TGen g -> TGen g -> Bool
compare :: TGen g -> TGen g -> Ordering
$ccompare :: forall g. Ord g => TGen g -> TGen g -> Ordering
Ord, Int -> TGen g -> ShowS
forall g. Show g => Int -> TGen g -> ShowS
forall g. Show g => [TGen g] -> ShowS
forall g. Show g => TGen g -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TGen g] -> ShowS
$cshowList :: forall g. Show g => [TGen g] -> ShowS
show :: TGen g -> String
$cshow :: forall g. Show g => TGen g -> String
showsPrec :: Int -> TGen g -> ShowS
$cshowsPrec :: forall g. Show g => Int -> TGen g -> ShowS
Show, Int -> TGen g -> (ShortByteString, TGen g)
Word32 -> TGen g -> (Word32, TGen g)
Word64 -> TGen g -> (Word64, TGen g)
TGen g -> (Int, Int)
TGen g -> (Int, TGen g)
TGen g -> (Word8, TGen g)
TGen g -> (Word16, TGen g)
TGen g -> (Word32, TGen g)
TGen g -> (Word64, TGen g)
TGen g -> (TGen g, TGen g)
forall g. RandomGen g => Int -> TGen g -> (ShortByteString, TGen g)
forall g. RandomGen g => Word32 -> TGen g -> (Word32, TGen g)
forall g. RandomGen g => Word64 -> TGen g -> (Word64, TGen g)
forall g. RandomGen g => TGen g -> (Int, Int)
forall g. RandomGen g => TGen g -> (Int, TGen g)
forall g. RandomGen g => TGen g -> (Word8, TGen g)
forall g. RandomGen g => TGen g -> (Word16, TGen g)
forall g. RandomGen g => TGen g -> (Word32, TGen g)
forall g. RandomGen g => TGen g -> (Word64, TGen g)
forall g. RandomGen g => TGen g -> (TGen g, TGen g)
forall g.
(g -> (Int, g))
-> (g -> (Word8, g))
-> (g -> (Word16, g))
-> (g -> (Word32, g))
-> (g -> (Word64, g))
-> (Word32 -> g -> (Word32, g))
-> (Word64 -> g -> (Word64, g))
-> (Int -> g -> (ShortByteString, g))
-> (g -> (Int, Int))
-> (g -> (g, g))
-> RandomGen g
split :: TGen g -> (TGen g, TGen g)
$csplit :: forall g. RandomGen g => TGen g -> (TGen g, TGen g)
genRange :: TGen g -> (Int, Int)
$cgenRange :: forall g. RandomGen g => TGen g -> (Int, Int)
genShortByteString :: Int -> TGen g -> (ShortByteString, TGen g)
$cgenShortByteString :: forall g. RandomGen g => Int -> TGen g -> (ShortByteString, TGen g)
genWord64R :: Word64 -> TGen g -> (Word64, TGen g)
$cgenWord64R :: forall g. RandomGen g => Word64 -> TGen g -> (Word64, TGen g)
genWord32R :: Word32 -> TGen g -> (Word32, TGen g)
$cgenWord32R :: forall g. RandomGen g => Word32 -> TGen g -> (Word32, TGen g)
genWord64 :: TGen g -> (Word64, TGen g)
$cgenWord64 :: forall g. RandomGen g => TGen g -> (Word64, TGen g)
genWord32 :: TGen g -> (Word32, TGen g)
$cgenWord32 :: forall g. RandomGen g => TGen g -> (Word32, TGen g)
genWord16 :: TGen g -> (Word16, TGen g)
$cgenWord16 :: forall g. RandomGen g => TGen g -> (Word16, TGen g)
genWord8 :: TGen g -> (Word8, TGen g)
$cgenWord8 :: forall g. RandomGen g => TGen g -> (Word8, TGen g)
next :: TGen g -> (Int, TGen g)
$cnext :: forall g. RandomGen g => TGen g -> (Int, TGen g)
RandomGen, Ptr (TGen g) -> IO (TGen g)
Ptr (TGen g) -> Int -> IO (TGen g)
Ptr (TGen g) -> Int -> TGen g -> IO ()
Ptr (TGen g) -> TGen g -> IO ()
TGen g -> Int
forall b. Ptr b -> Int -> IO (TGen g)
forall b. Ptr b -> Int -> TGen g -> IO ()
forall g. Storable g => Ptr (TGen g) -> IO (TGen g)
forall g. Storable g => Ptr (TGen g) -> Int -> IO (TGen g)
forall g. Storable g => Ptr (TGen g) -> Int -> TGen g -> IO ()
forall g. Storable g => Ptr (TGen g) -> TGen g -> IO ()
forall g. Storable g => TGen g -> Int
forall g b. Storable g => Ptr b -> Int -> IO (TGen g)
forall g b. Storable g => Ptr b -> Int -> TGen g -> IO ()
forall a.
(a -> Int)
-> (a -> Int)
-> (Ptr a -> Int -> IO a)
-> (Ptr a -> Int -> a -> IO ())
-> (forall b. Ptr b -> Int -> IO a)
-> (forall b. Ptr b -> Int -> a -> IO ())
-> (Ptr a -> IO a)
-> (Ptr a -> a -> IO ())
-> Storable a
poke :: Ptr (TGen g) -> TGen g -> IO ()
$cpoke :: forall g. Storable g => Ptr (TGen g) -> TGen g -> IO ()
peek :: Ptr (TGen g) -> IO (TGen g)
$cpeek :: forall g. Storable g => Ptr (TGen g) -> IO (TGen g)
pokeByteOff :: forall b. Ptr b -> Int -> TGen g -> IO ()
$cpokeByteOff :: forall g b. Storable g => Ptr b -> Int -> TGen g -> IO ()
peekByteOff :: forall b. Ptr b -> Int -> IO (TGen g)
$cpeekByteOff :: forall g b. Storable g => Ptr b -> Int -> IO (TGen g)
pokeElemOff :: Ptr (TGen g) -> Int -> TGen g -> IO ()
$cpokeElemOff :: forall g. Storable g => Ptr (TGen g) -> Int -> TGen g -> IO ()
peekElemOff :: Ptr (TGen g) -> Int -> IO (TGen g)
$cpeekElemOff :: forall g. Storable g => Ptr (TGen g) -> Int -> IO (TGen g)
alignment :: TGen g -> Int
$calignment :: forall g. Storable g => TGen g -> Int
sizeOf :: TGen g -> Int
$csizeOf :: forall g. Storable g => TGen g -> Int
Storable, TGen g -> ()
forall g. NFData g => TGen g -> ()
forall a. (a -> ()) -> NFData a
rnf :: TGen g -> ()
$crnf :: forall g. NFData g => TGen g -> ()
NFData)
newTGenM :: g -> STM (TGenM g)
newTGenM :: forall g. g -> STM (TGenM g)
newTGenM = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g. TVar g -> TGenM g
TGenM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> STM (TVar a)
newTVar
newTGenMIO :: MonadIO m => g -> m (TGenM g)
newTGenMIO :: forall (m :: * -> *) g. MonadIO m => g -> m (TGenM g)
newTGenMIO g
g = forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (forall g. TVar g -> TGenM g
TGenM forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. a -> IO (TVar a)
newTVarIO g
g)
instance RandomGen g => StatefulGen (TGenM g) STM where
uniformWord32R :: Word32 -> TGenM g -> STM Word32
uniformWord32R Word32
r = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen (forall g. RandomGen g => Word32 -> g -> (Word32, g)
genWord32R Word32
r)
{-# INLINE uniformWord32R #-}
uniformWord64R :: Word64 -> TGenM g -> STM Word64
uniformWord64R Word64
r = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen (forall g. RandomGen g => Word64 -> g -> (Word64, g)
genWord64R Word64
r)
{-# INLINE uniformWord64R #-}
uniformWord8 :: TGenM g -> STM Word8
uniformWord8 = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen forall g. RandomGen g => g -> (Word8, g)
genWord8
{-# INLINE uniformWord8 #-}
uniformWord16 :: TGenM g -> STM Word16
uniformWord16 = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen forall g. RandomGen g => g -> (Word16, g)
genWord16
{-# INLINE uniformWord16 #-}
uniformWord32 :: TGenM g -> STM Word32
uniformWord32 = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen forall g. RandomGen g => g -> (Word32, g)
genWord32
{-# INLINE uniformWord32 #-}
uniformWord64 :: TGenM g -> STM Word64
uniformWord64 = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen forall g. RandomGen g => g -> (Word64, g)
genWord64
{-# INLINE uniformWord64 #-}
uniformShortByteString :: Int -> TGenM g -> STM ShortByteString
uniformShortByteString Int
n = forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen (forall g. RandomGen g => Int -> g -> (ShortByteString, g)
genShortByteString Int
n)
instance RandomGen g => FrozenGen (TGen g) STM where
type MutableGen (TGen g) STM = TGenM g
freezeGen :: MutableGen (TGen g) STM -> STM (TGen g)
freezeGen = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall g. g -> TGen g
TGen forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. TVar a -> STM a
readTVar forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall g. TGenM g -> TVar g
unTGenM
thawGen :: TGen g -> STM (MutableGen (TGen g) STM)
thawGen (TGen g
g) = forall g. g -> STM (TGenM g)
newTGenM g
g
applyTGen :: (g -> (a, g)) -> TGenM g -> STM a
applyTGen :: forall g a. (g -> (a, g)) -> TGenM g -> STM a
applyTGen g -> (a, g)
f (TGenM TVar g
tvar) = do
g
g <- forall a. TVar a -> STM a
readTVar TVar g
tvar
case g -> (a, g)
f g
g of
(a
a, !g
g') -> a
a forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall a. TVar a -> a -> STM ()
writeTVar TVar g
tvar g
g'
{-# INLINE applyTGen #-}