distribution-1.0.0.0: Finite discrete probability distributions.

Safe HaskellSafe-Inferred

Data.Distribution.Sample

Contents

Description

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.

Synopsis

Generator

data Generator a Source

Generator of random values of type a.

Can be created in linear time from distributions and sampled in constant time.

Instances

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.