Random samplers for some common distributions, based on splitmix.


Version on this page:
LTS Haskell 20.24:1.0.0
Stackage Nightly 2023-06-04:1.0.0
Latest on Hackage:1.0.0

See all snapshots splitmix-distributions appears in

BSD-3-Clause licensed by Marco Zocca
Maintained by ocramz
This version can be pinned in stack with:splitmix-distributions-,1574

Module documentation for

Used by 1 package in lts-18.28(full list with versions):


Random samplers for some common distributions, as well as a convenient interface for composing them, based on splitmix.


Compose your random sampler out of simpler ones thanks to the Applicative and Monad interface, e.g. this is how you would declare and sample a binary mixture of Gaussian random variables:

import Control.Monad (replicateM)
import System.Random.SplitMix.Distributions (Gen, sample, bernoulli, normal)

process :: Gen Double
process = do
    coin <- bernoulli 0.7
    if coin
        normal 0 2
        normal 3 1

dataset :: [Double]
dataset = sample 1234 $ replicateM 20 process

and sample your data in a pure (sample) or monadic (sampleT) setting.

Implementation details

The library is built on top of splitmix, so the caveats on safety and performance that apply there are relevant here as well.


0.9 :

  • ensure it builds with ghc 8.6.5 (== stackage lts 14.27) as well
  • relax lower bound

0.8 :

  • add exceptions dependency
  • add MonadThrow (GenT m) instance

0.7 :

  • add sampleIO, samplesIO
  • clarify pure vs IO-based sampling in the docs

0.6 :

  • add Chinese Restaurant Process

0.5 :

  • add Log-normal, Laplace, Weibull distributions

0.4 :

  • add Discrete, Categorical, Zipf-Mandelbrot distributions

0.3 :

  • type signatures of all generators are now parametrized over some Monad m rather than Identity. This allows for more flexibility on the use site.

0.2 :

  • add Pareto, Dirichlet, multinomial distributions