Class DiscreteUniformSampler.PowerOf2RangeDiscreteUniformSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler.AbstractDiscreteUniformSampler
org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler.PowerOf2RangeDiscreteUniformSampler
- All Implemented Interfaces:
DiscreteSampler
,SharedStateDiscreteSampler
,SharedStateSampler<SharedStateDiscreteSampler>
- Enclosing class:
DiscreteUniformSampler
private static final class DiscreteUniformSampler.PowerOf2RangeDiscreteUniformSampler
extends DiscreteUniformSampler.AbstractDiscreteUniformSampler
Discrete uniform distribution sampler when the range is a power of 2 and greater than 1.
This sampler assumes the lower bound of the range is 0.
Note: This cannot be used when the range is 1 (2^0) as the shift would be 32-bits which is ignored by the shift operator.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
Bit shift to apply to the integer sample.Fields inherited from class org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler.AbstractDiscreteUniformSampler
rng
-
Constructor Summary
ConstructorsConstructorDescriptionPowerOf2RangeDiscreteUniformSampler
(UniformRandomProvider rng, int range) PowerOf2RangeDiscreteUniformSampler
(UniformRandomProvider rng, DiscreteUniformSampler.PowerOf2RangeDiscreteUniformSampler 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
-
shift
private final int shiftBit shift to apply to the integer sample.
-
-
Constructor Details
-
PowerOf2RangeDiscreteUniformSampler
PowerOf2RangeDiscreteUniformSampler(UniformRandomProvider rng, int range) - Parameters:
rng
- Generator of uniformly distributed random numbers.range
- Maximum range of the sample (exclusive). Must be a power of 2 greater than 2^0.
-
PowerOf2RangeDiscreteUniformSampler
PowerOf2RangeDiscreteUniformSampler(UniformRandomProvider rng, DiscreteUniformSampler.PowerOf2RangeDiscreteUniformSampler 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
-