Fast, high quality pseudo random number generation

Version on this page:
LTS Haskell 22.30:
Stackage Nightly 2024-07-21:
Latest on Hackage:

See all snapshots mwc-random appears in

BSD-3-Clause licensed and maintained by Bryan O'Sullivan
This version can be pinned in stack with:mwc-random-,3372

Efficient, general purpose pseudo-random number generation

Build Status

This package provides the System.Random.MWC module, a Haskell library for generating high-quality pseudo-random numbers in a space- and time-efficient way.

Get involved!

Please report bugs via the github issue tracker.

Master git git repository:

  • git clone git://


This library is written and maintained by Bryan O’Sullivan, [email protected].


Changes in

  • Doctests on 32-bit platforms are fixed. (#79)

Changes in

  • Bug in generation of Int/Word in both uniform and uniformR is fixed. (#75)

Changes in

  • withSystemRandomST and createSystemSeed are added.

  • withSystemRandom is deprecated.

  • random>=1.2 is dependency of mwc-random.

  • Instances for type classes StatefulGen & FrozenGen defined in random-1.2 are added for Gen.

  • Functions in System.Random.MWC.Distributions and System.Random.MWC.CondensedTable now work with arbitrary StatefulGen

  • System.Random.MWC.uniformVector now works with arbitrary StatefulGen as well and uses in-place initialization instead of generateM. It should be faster for anything but IO and ST (those shoud remain same).

Changes in

  • Low level functions for acquiring random data for initialization of PRGN state is moved to System.Random.MWC.SeedSource module

  • Ensure that carry is always correct when restoring PRNG state from seed. Only affects users who create 258 element seed manually. (#63, #65)

Changes in

  • tablePoisson now can handle λ>1923, see #59 for details. That required intoduction of dependency on math-functions.

Changes in

  • logCategorical added

Changes in

  • withSystemRandom uses RtlGenRandom for seeding generator on windows

Changes in

  • primitive-0.6 compatibility

Changes in

  • Monadic variant of vector shuffle added: uniformShuffleM

  • Context on uniformShuffle loosened

Changes in

  • Fixed crash during gen. initialization on Windows when stderr is not available (#36).

Changes in

  • Generators for beta, Bernoully, Dirichlet and categorical distributions added.

  • Functions for generating random shuffles added.

Changes in

  • GHC 7.9 support

Changes in

  • Long standing performance problem in normal distribution fixed (#16)

Changes in

  • createSystemRandom added

Changes in

  • Workaround for GHC bug 8072 (bug 25). GHC 7.6 on 32-bit platrofms is affected.

  • Generators for truncated exponential and geometric distributions added.

Changes in

  • Fucntion asGenIO and asGenST added.

  • Generation of discrete random variates using condensed tables methed. Tables for Poisson and binomial distributions are provided.