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
private static final class UniformLongSampler.SmallRangeUniformLongSampler
extends 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 longLimit of the uniform range (inclusive) to sample a positive long.private final longMaximum 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 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 org.apache.commons.rng.sampling.distribution.UniformLongSampler
of, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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 ofnminus 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: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
-