## Class MarsagliaTsangWangDiscreteSampler

• java.lang.Object
• org.apache.commons.rng.sampling.distribution.MarsagliaTsangWangDiscreteSampler

• public final class MarsagliaTsangWangDiscreteSampler
extends Object
Sampler for a discrete distribution using an optimised look-up table.
• The method requires 30-bit integer probabilities that sum to 230 as described in George Marsaglia, Wai Wan Tsang, Jingbo Wang (2004) Fast Generation of Discrete Random Variables. Journal of Statistical Software. Vol. 11, Issue. 3, pp. 1-11.

Sampling uses 1 call to UniformRandomProvider.nextInt().

Memory requirements depend on the maximum number of possible sample values, n, and the values for the probabilities. Storage is optimised for n. The worst case scenario is a uniform distribution of the maximum sample size. This is capped at 0.06MB for n <=  28, 17.0MB for n <=  216, and 4.3GB for n <= 230. Realistic requirements will be in the kB range.

The sampler supports the following distributions:

• Enumerated distribution (probabilities must be provided for each sample)
• Poisson distribution up to mean = 1024
• Binomial distribution up to trials = 65535
Since:
1.3
Margsglia, et al (2004) JSS Vol. 11, Issue 3
• ### Nested Class Summary

Nested Classes
Modifier and Type Class Description
static class  MarsagliaTsangWangDiscreteSampler.Binomial
Create a sampler for the Binomial distribution.
static class  MarsagliaTsangWangDiscreteSampler.Enumerated
Create a sampler for an enumerated distribution of n values each with an associated probability.
static class  MarsagliaTsangWangDiscreteSampler.Poisson
Create a sampler for the Poisson distribution.

• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait