Safe Haskell | Safe-Inferred |
---|
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 aSource
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 aSource
Picks a random value from the generator.
Runs in constant O(1)
time.