module System.Random.MWC.Extended (
      module System.Random.MWC
    , withRng
) where



import           Control.Monad.Primitive
import qualified Data.Vector             as V
import           System.Random.MWC



-- | Convenience function to generate a random number 'Gen'erator.
withRng :: PrimMonad m => Integral seed => [seed] -> (Gen (PrimState m) -> m a) -> m a
withRng :: forall (m :: * -> *) seed a.
(PrimMonad m, Integral seed) =>
[seed] -> (Gen (PrimState m) -> m a) -> m a
withRng [seed]
seed Gen (PrimState m) -> m a
actions = Vector Word32 -> m (Gen (PrimState m))
forall (m :: * -> *) (v :: * -> *).
(PrimMonad m, Vector v Word32) =>
v Word32 -> m (Gen (PrimState m))
initialize ((seed -> Word32) -> Vector seed -> Vector Word32
forall a b. (a -> b) -> Vector a -> Vector b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap seed -> Word32
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([seed] -> Vector seed
forall a. [a] -> Vector a
V.fromList [seed]
seed)) m (Gen (PrimState m)) -> (Gen (PrimState m) -> m a) -> m a
forall a b. m a -> (a -> m b) -> m b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Gen (PrimState m) -> m a
actions