Safe Haskell | Safe |
---|---|
Language | Haskell98 |
This modules provides ways to randomly and efficiently sample values from distributions.
Walker's alias method is used internally, so that values can be sampled in constant time.
- data Generator a
- fromDistribution :: Distribution a -> Generator a
- safeFromDistribution :: Distribution a -> Maybe (Generator a)
- sample :: RandomGen g => Generator a -> g -> (a, g)
- getSample :: MonadRandom m => Generator a -> m a
Generator
Generator of random values of type a
.
Can be created in linear time from distributions and sampled in constant time.
Building
fromDistribution :: Distribution a -> Generator a Source #
Creates a generator from the given non-empty distribution.
Runs in O(n)
time where n
is the size of the distribution.
safeFromDistribution :: Distribution a -> Maybe (Generator a) Source #
Safe version of fromDistribution
. Returns Nothing
when the
given distribution is empty.
Sampling
sample :: RandomGen g => Generator a -> g -> (a, g) Source #
Picks a random value from the generator.
Runs in constant O(1)
time.
getSample :: MonadRandom m => Generator a -> m a Source #
Picks a random value from the generator.
Runs in constant O(1)
time.