Class UniformLongSampler.SmallRangeUniformLongSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.UniformLongSampler
org.apache.commons.rng.sampling.distribution.UniformLongSampler.SmallRangeUniformLongSampler
- All Implemented Interfaces:
LongSampler
,SharedStateLongSampler
,SharedStateSampler<SharedStateLongSampler>
- Enclosing class:
UniformLongSampler
Discrete uniform distribution sampler when the range is small
enough to fit in a positive long.
This sampler assumes the lower bound of the range is 0 and the range is
non-zero.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final long
Limit of the uniform range (inclusive) to sample a positive long.private final long
Maximum range of the sample (exclusive).Fields inherited from class org.apache.commons.rng.sampling.distribution.UniformLongSampler
rng
-
Constructor Summary
ConstructorsConstructorDescriptionSmallRangeUniformLongSampler
(UniformRandomProvider rng, long range) SmallRangeUniformLongSampler
(UniformRandomProvider rng, UniformLongSampler.SmallRangeUniformLongSampler 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
-
n
private final long nMaximum range of the sample (exclusive). -
limit
private final long limitLimit of the uniform range (inclusive) to sample a positive long. This is the largest positive multiple ofn
minus 1:floor(2^63 / n) * n - 1
. The -1 changes the limit to an inclusive bound and allows support for a power of 2 range.
-
-
Constructor Details
-
SmallRangeUniformLongSampler
SmallRangeUniformLongSampler(UniformRandomProvider rng, long range) - Parameters:
rng
- Generator of uniformly distributed random numbers.range
- Maximum range of the sample (exclusive).
-
SmallRangeUniformLongSampler
SmallRangeUniformLongSampler(UniformRandomProvider rng, UniformLongSampler.SmallRangeUniformLongSampler 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
-