{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnicodeSyntax #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.ByteString.Random.PCG
( random
, randomGen
) where
import Data.ByteString (ByteString)
import Numeric.Natural (Natural)
import System.Random.PCG (uniform, GenIO, withSystemRandom)
import Data.ByteString.Random.Internal
instance (g ~ GenIO) ⇒ RandomWords g where
uniformW8 :: g -> IO Word8
uniformW8 = g -> IO Word8
forall a g (m :: * -> *). (Variate a, Generator g m) => g -> m a
uniform
{-# INLINE uniformW8 #-}
uniformW64 :: g -> IO Word64
uniformW64 = g -> IO Word64
forall a g (m :: * -> *). (Variate a, Generator g m) => g -> m a
uniform
{-# INLINE uniformW64 #-}
{-# SPECIALIZE generate ∷ GenIO → Natural → IO ByteString #-}
randomGen
∷ GenIO
→ Natural
→ IO ByteString
randomGen :: GenIO -> Natural -> IO ByteString
randomGen = GenIO -> Natural -> IO ByteString
forall g. RandomWords g => g -> Natural -> IO ByteString
generate
{-# INLINE randomGen #-}
random
∷ Natural
→ IO ByteString
random :: Natural -> IO ByteString
random Natural
n = (GenIO -> IO ByteString) -> IO ByteString
forall a. (GenIO -> IO a) -> IO a
withSystemRandom ((GenIO -> IO ByteString) -> IO ByteString)
-> (GenIO -> IO ByteString) -> IO ByteString
forall a b. (a -> b) -> a -> b
$ (GenIO -> Natural -> IO ByteString)
-> Natural -> GenIO -> IO ByteString
forall a b c. (a -> b -> c) -> b -> a -> c
flip GenIO -> Natural -> IO ByteString
randomGen Natural
n