HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulemwc-random-0.15.2.0Haskell2010

System.Random.MWC.Distributions

Pseudo-random number generation for non-uniform distributions.

  • 17 values
  • Packagemwc-random-0.15.2.0
  • Exports17
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceDistributions.hs

Variates: non-uniformly distributed values

0 declarations

Continuous distributions

valuestandard :: StatefulGen g m => g -> m Double
#

Generate a normally distributed random variate with zero mean and unit variance.

The implementation uses Doornik's modified ziggurat algorithm. Compared to the ziggurat algorithm usually used, this is slower, but generates more independent variates that pass stringent tests of randomness.

valuechiSquare
  1. :: StatefulGen g m
  2. => Int

    Number of degrees of freedom

  3. -> g

    Generator

  4. -> m Double
#

Random variate generator for the chi square distribution.

Discrete distribution

valuecategorical
  1. :: (StatefulGen g m, Vector v Double)
  2. => v Double

    List of weights [>0]

  3. -> g

    Generator

  4. -> m Int
#

Random variate generator for categorical distribution.

Note that if you need to generate a lot of variates functions System.Random.MWC.CondensedTable will offer better performance. If only few is needed this function will faster since it avoids costs of setting up table.

valuegeometric0
  1. :: StatefulGen g m
  2. => Double

    p success probability lies in (0,1]

  3. -> g

    Generator

  4. -> m Int
#

Random variate generator for the geometric distribution, computing the number of failures before success. Distribution's support is [0..].

valuegeometric1
  1. :: StatefulGen g m
  2. => Double

    p success probability lies in (0,1]

  3. -> g

    Generator

  4. -> m Int
#

Random variate generator for geometric distribution for number of trials. Distribution's support is [1..] (i.e. just geometric0 shifted by 1).

valuebernoulli
  1. :: StatefulGen g m
  2. => Double

    Probability of success (returning True)

  3. -> g

    Generator

  4. -> m Bool
#

Random variate generator for Bernoulli distribution

valuebinomial
  1. :: StatefulGen g m
  2. => Int

    Number of trials, must be positive.

  3. -> Double

    Probability of success p \in [0,1]

  4. -> g

    Generator

  5. -> m Int
#

Random variate generator for Binomial distribution. Will throw exception when parameters are out range.

The probability of getting exactly k successes in n trials is given by the probability mass function:

f(k;n,p) = \Pr(X = k) = \binom n k p^k(1-p)^{n-k}

Multivariate

Permutations

3 declarations
valueuniformShuffle
  1. :: (StatefulGen g m, PrimMonad m, Vector v a)
  2. => v a
  3. -> g
  4. -> m (v a)
#

Random variate generator for a uniformly distributed shuffle (all shuffles are equiprobable) of a vector. It uses Fisher-Yates shuffle algorithm.

References

0 declarations