cardano-crypto-wrapper-1.3.0: Cryptographic primitives used in the Cardano project
Safe Haskell None
Language Haskell2010

Cardano.Crypto.Random

Description

Secure generation of random numbers and ByteString s

Synopsis

Documentation

newtype SecureRandom a Source #

You can use runSecureRandom on any MonadRandom computation to use the operating system entropy source to satisfy every request for randomness. That is, this does not use a fixed entropy pool shared across all requests; it gets entropy from the operating system for every request.

This is suitable for key generation but is inappropriate for other uses since it can quickly drain the operating system entropy.

deterministic :: ByteString -> MonadPseudoRandom ChaChaDRG a -> a Source #

You can use deterministic on any MonadRandom computation to make it use a seed (hopefully produced by a Really Secureā„¢ randomness source). The seed has to have enough entropy to make this function secure.

randomNumber :: forall m. MonadRandom m => Integer -> m Integer Source #

Generate a random number in range [0, n)

We want to avoid modulo bias, so we use the arc4random_uniform implementation (http:/ stackoverflow.com a 20051580 615030). Specifically, we repeatedly generate a random number in range [0, 2^x) until we hit on something outside of [0, 2^x mod n), which means that it'll be in range [2^x mod n, 2^x). The amount of numbers in this interval is guaranteed to be divisible by n, and thus applying mod to it will be safe.

randomNumberInRange :: MonadRandom m => Integer -> Integer -> m Integer Source #

Generate a random number in range [a, b]