Safe Haskell | None |
---|
- getRandomR :: Random a => (a, a) -> Rand a
- getRandom :: Random a => Rand a
- getNormal2 :: Rand (Double, Double)
- getNormal :: Rand Double
- randomSample :: Int -> [a] -> Rand [a]
- shuffle :: [a] -> Rand [a]
- withProbability :: Double -> (a -> Rand a) -> a -> Rand a
- getBool :: Rand Bool
- getInt :: Rand Int
- getWord :: Rand Word
- getInt64 :: Rand Int64
- getWord64 :: Rand Word64
- getDouble :: Rand Double
- runRandom :: Rand a -> PureMT -> (a, PureMT)
- evalRandom :: Rand a -> PureMT -> a
- newPureMT :: IO PureMT
- data Rand a
- class Random a
- data PureMT
Random numbers from given range
getRandomR :: Random a => (a, a) -> Rand aSource
Yield a new randomly selected value of type a
in the range (lo, hi)
.
See randomR
for details.
getRandom :: Random a => Rand aSource
Yield a new randomly selected value of type a
.
See random
for details.
Probability distributions
getNormal2 :: Rand (Double, Double)Source
Yield two randomly selected values which follow standard normal distribution.
Random samples and shuffles
randomSample :: Int -> [a] -> Rand [a]Source
Take at most n random elements from the list. Preserve order.
Building blocks
withProbability :: Double -> (a -> Rand a) -> a -> Rand aSource
Modify value with probability p
. Return the unchanged value with probability 1-p
.
Re-exports from random number generator packages
runRandom :: Rand a -> PureMT -> (a, PureMT)
Run a random computation using the generator g
, returning the result
and the updated generator.
evalRandom :: Rand a -> PureMT -> a
Evaluate a random computation using the mersenne generator g
. Note that the
generator g
is not returned, so there's no way to recover the
updated version of g
.
data Rand a
A basic random monad, for generating random numbers from pure mersenne twisters.
class Random a
With a source of random number supply in hand, the Random
class allows the
programmer to extract random values of a variety of types.