Safe Haskell | None |
---|---|
Language | Haskell98 |
Synopsis
- getRandomR :: Random a => (a, a) -> Rand a
- getRandom :: Random a => Rand a
- getNormal2 :: Rand (Double, Double)
- getNormal :: Rand Double
- randomSample :: Int -> [a] -> Rand [a]
- randomSampleIndices :: Int -> Int -> Rand [Int]
- 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
- runRand :: Rand g a -> g -> (a, g)
- evalRand :: Rand g a -> g -> a
- newPureMT :: IO PureMT
- liftRand :: (g -> (a, g)) -> Rand g a
- type Rand = Rand PureMT
- class Random a
- data PureMT
Random numbers from given range
getRandomR :: Random a => (a, a) -> Rand a Source #
Yield a new randomly selected value of type a
in the range (lo, hi)
.
See randomR
for details.
getRandom :: Random a => Rand a Source #
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.
getNormal :: Rand Double Source #
Yield one randomly selected value from standard normal distribution.
Random samples and shuffles
randomSample :: Int -> [a] -> Rand [a] Source #
Take at most n random elements from the list. Preserve order.
randomSampleIndices :: Int -> Int -> Rand [Int] Source #
Select sampleSize
numbers in the range from 0
to (populationSize-1)
.
The function works best when sampleSize
is much smaller than populationSize
.
Building blocks
withProbability :: Double -> (a -> Rand a) -> a -> Rand a Source #
Modify value with probability p
. Return the unchanged value with probability 1-p
.
Re-exports from random number generator packages
:: Rand g a | generator-passing computation to execute |
-> g | initial generator |
-> (a, g) | return value and final generator |
Unwrap a random monad computation as a function.
(The inverse of liftRand
.)
:: Rand g a | generator-passing computation to execute |
-> g | initial generator |
-> a | return value of the random computation |
Create a new PureMT generator, using the clocktime as the base for the seed.
:: (g -> (a, g)) | pure random transformer |
-> Rand g a | equivalent generator-passing computation |
Construct a random monad computation from a function.
(The inverse of runRand
.)
With a source of random number supply in hand, the Random
class allows the
programmer to extract random values of a variety of types.