Class UniformLongSampler.PowerOf2RangeUniformLongSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.UniformLongSampler
org.apache.commons.rng.sampling.distribution.UniformLongSampler.PowerOf2RangeUniformLongSampler
- All Implemented Interfaces:
LongSampler, SharedStateLongSampler, SharedStateSampler<SharedStateLongSampler>
- Enclosing class:
UniformLongSampler
private static final class UniformLongSampler.PowerOf2RangeUniformLongSampler
extends UniformLongSampler
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 64-bits which is ignored by the shift operator.
- Since:
- 1.4
-
Field Summary
FieldsFields inherited from class UniformLongSampler
rng -
Constructor Summary
ConstructorsConstructorDescriptionPowerOf2RangeUniformLongSampler(UniformRandomProvider rng, long range) PowerOf2RangeUniformLongSampler(UniformRandomProvider rng, UniformLongSampler.PowerOf2RangeUniformLongSampler source) -
Method Summary
Modifier and TypeMethodDescriptionlongsample()Creates alongsample.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 UniformLongSampler
of, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface LongSampler
samples, samples
-
Field Details
-
shift
private final int shiftBit shift to apply to the long sample.
-
-
Constructor Details
-
PowerOf2RangeUniformLongSampler
PowerOf2RangeUniformLongSampler(UniformRandomProvider rng, long 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.
-
PowerOf2RangeUniformLongSampler
PowerOf2RangeUniformLongSampler(UniformRandomProvider rng, UniformLongSampler.PowerOf2RangeUniformLongSampler source) - Parameters:
rng- Generator of uniformly distributed random numbers.source- Source to copy.
-
-
Method Details
-
sample
public long sample()Description copied from interface:LongSamplerCreates alongsample.- Returns:
- a sample.
-
withUniformRandomProvider
Description copied from class:UniformLongSamplerCreate a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Specified by:
withUniformRandomProviderin interfaceSharedStateSampler<SharedStateLongSampler>- Specified by:
withUniformRandomProviderin classUniformLongSampler- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-