-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A monad for using CryptoRandomGen -- -- A monad for using CryptoRandomGen @package monadcryptorandom @version 0.2 -- | Much like the MonadRandom package -- (Control.Monad.Random), this module provides plumbing for the -- CryptoRandomGen generators. module Control.Monad.Crypto.Random -- | CRandom a is much like the Random class from the -- System.Random module in the random package. The main -- difference is CRandom builds on crypto-api's -- CryptoRandomGen, so it allows explicit failure. -- -- crandomR (low,high) g as typically instantiated will generate -- a value between [low, high] inclusively, swapping the pair if high -- < low. -- -- Provided instances for crandom g generates randoms between -- the bounds and between +/- 2^256 for Integer. -- -- The crandomR function has degraded (theoretically unbounded, -- probabilistically decent) performance the closer your range size (high -- - low) is to 2^n (from the top). class CRandom a crandom :: (CRandom a, CryptoRandomGen g) => g -> Either GenError (a, g) crandomR :: (CRandom a, CryptoRandomGen g) => (a, a) -> g -> Either GenError (a, g) crandoms :: (CRandom a, CryptoRandomGen g) => g -> [a] crandomRs :: (CRandom a, CryptoRandomGen g) => (a, a) -> g -> [a] -- | MonadCryptoRandom m represents a monad that can produce -- random values (or fail with a GenError). It is suggestd you use -- the CRandT transformer in your monad stack. class MonadError GenError m => MonadCryptoRandom m getCRandom :: (MonadCryptoRandom m, CRandom a) => m a getCRandomR :: (MonadCryptoRandom m, CRandom a) => (a, a) -> m a getBytes :: MonadCryptoRandom m => Int -> m ByteString getBytesWithEntropy :: MonadCryptoRandom m => Int -> ByteString -> m ByteString doReseed :: MonadCryptoRandom m => ByteString -> m () -- | CRandT is the transformer suggested for MonadCryptoRandom. data CRandT g m a -- | Simple users of generators can use CRand for quick and easy generation -- of randoms. See below for a simple use of newGenIO (from -- crypto-api), getCRandom, getBytes, and -- runCRandom. -- --
--   getRandPair = do
--      int <- getCRandom
--      bytes <- getBytes 100
--      return (int, bytes)
--   
--   func = do
--      g <- newGenIO
--      case runCRand getRandPair g of
--          Right ((int,bytes), g') -> useRandomVals (int,bytes)
--          Left x -> handleGenError x
--   
type CRand g = CRandT g Identity runCRandT :: CRandT g m a -> g -> m (Either GenError (a, g)) evalCRandT :: Monad m => CRandT g m a -> g -> m (Either GenError a) runCRand :: CRand g a -> g -> Either GenError (a, g) evalCRand :: CRand g a -> g -> Either GenError a instance Monad m => MonadError GenError (CRandT g m) instance Monad m => Monad (CRandT g m) instance Error GenError instance (Monad m, CryptoRandomGen g) => MonadCryptoRandom (CRandT g m) instance MonadTrans (CRandT g) instance CRandom Int64 instance CRandom Int32 instance CRandom Int16 instance CRandom Int8 instance CRandom Word64 instance CRandom Word32 instance CRandom Word16 instance CRandom Word8 instance CRandom Int instance CRandom Integer