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
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.
-
Field Summary
FieldsFields inherited from class org.apache.commons.rng.sampling.distribution.UniformLongSampler
rng
-
Constructor Summary
ConstructorsConstructorDescriptionPowerOf2RangeUniformLongSampler
(UniformRandomProvider rng, long range) PowerOf2RangeUniformLongSampler
(UniformRandomProvider rng, UniformLongSampler.PowerOf2RangeUniformLongSampler source) -
Method Summary
Modifier and TypeMethodDescriptionlong
sample()
Creates along
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.UniformLongSampler
of, 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.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:LongSampler
Creates along
sample.- Returns:
- a sample.
-
withUniformRandomProvider
Description copied from class:UniformLongSampler
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Specified by:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateLongSampler>
- Specified by:
withUniformRandomProvider
in classUniformLongSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-