Class DiscreteUniformSampler.SmallRangeDiscreteUniformSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler.AbstractDiscreteUniformSampler
org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler.SmallRangeDiscreteUniformSampler
- All Implemented Interfaces:
DiscreteSampler
,SharedStateDiscreteSampler
,SharedStateSampler<SharedStateDiscreteSampler>
- Enclosing class:
DiscreteUniformSampler
private static class DiscreteUniformSampler.SmallRangeDiscreteUniformSampler
extends DiscreteUniformSampler.AbstractDiscreteUniformSampler
Discrete uniform distribution sampler when the range is small
enough to fit in a positive integer.
This sampler assumes the lower bound of the range is 0.
Implements the algorithm of Lemire (2019).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long
Maximum range of the sample (exclusive).private final long
The level below which samples are rejected based on the fraction remainder.Fields inherited from class org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler.AbstractDiscreteUniformSampler
rng
-
Constructor Summary
ConstructorsConstructorDescriptionSmallRangeDiscreteUniformSampler
(UniformRandomProvider rng, int range) SmallRangeDiscreteUniformSampler
(UniformRandomProvider rng, DiscreteUniformSampler.SmallRangeDiscreteUniformSampler source) -
Method Summary
Modifier and TypeMethodDescriptionint
sample()
Creates anint
sample.Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.Methods inherited from class org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler.AbstractDiscreteUniformSampler
toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.rng.sampling.distribution.DiscreteSampler
samples, samples
-
Field Details
-
n
private final long nMaximum range of the sample (exclusive). -
threshold
private final long thresholdThe level below which samples are rejected based on the fraction remainder.Any remainder below this denotes that there are still floor(2^32 / n) more observations of this sample from the interval [0, 2^32), where n is the range.
-
-
Constructor Details
-
SmallRangeDiscreteUniformSampler
SmallRangeDiscreteUniformSampler(UniformRandomProvider rng, int range) - Parameters:
rng
- Generator of uniformly distributed random numbers.range
- Maximum range of the sample (exclusive).
-
SmallRangeDiscreteUniformSampler
SmallRangeDiscreteUniformSampler(UniformRandomProvider rng, DiscreteUniformSampler.SmallRangeDiscreteUniformSampler source) - Parameters:
rng
- Generator of uniformly distributed random numbers.source
- Source to copy.
-
-
Method Details
-
sample
public int sample()Description copied from interface:DiscreteSampler
Creates anint
sample.- Returns:
- a sample.
-
withUniformRandomProvider
Description copied from interface:SharedStateSampler
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-