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.CondensedTable

Table-driven generation of random variates. This approach can generate random variates in O(1) time for the supported distributions, at a modest cost in initialization time.

  • 3 types
  • 6 values
  • Packagemwc-random-0.15.2.0
  • Exports9
  • LanguageHaskell2010
  • LicenceBSD-2-Clause
  • SourceCondensedTable.hs

Condensed tables

4 declarations
datadata CondensedTable (v :: Type -> Type) a
#

A lookup table for arbitrary discrete distributions. It allows the generation of random variates in O(1). Note that probability is quantized in units of 1/2^32, and all distributions with infinite support (e.g. Poisson) should be truncated.

Constructors for tables

3 declarations
valuetableFromProbabilities
  1. :: (Vector v (a, Word32), Vector v (a, Double), Vector v a, Vector v Word32)
  2. => v (a, Double)
  3. -> CondensedTable v a
#

Generate a condensed lookup table from a list of outcomes with given probabilities. The vector should be non-empty and the probabilities should be non-negative and sum to 1. If this is not the case, this algorithm will construct a table for some distribution that may bear no resemblance to what you intended.

valuetableFromIntWeights
  1. :: (Vector v (a, Word32), Vector v a, Vector v Word32)
  2. => v (a, Word32)
  3. -> CondensedTable v a
#

Generate a condensed lookup table from integer weights. Weights should sum to 2^32 at least approximately. This function will correct small deviations from 2^32 such as arising from rounding errors. But for large deviations it's likely to product incorrect result with terrible performance.

Disrete distributions

Create a lookup table for the Poisson distribution. Note that table construction may have significant cost. For λ < 100 it takes as much time to build table as generation of 1000-30000 variates.

References

0 declarations