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 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
Fields Modifier and Type Field Description private long
limit
Limit of the uniform range (inclusive) to sample a positive long.private long
n
Maximum range of the sample (exclusive).-
Fields inherited from class org.apache.commons.rng.sampling.distribution.UniformLongSampler
rng
-
-
Constructor Summary
Constructors Constructor Description SmallRangeUniformLongSampler(UniformRandomProvider rng, long range)
SmallRangeUniformLongSampler(UniformRandomProvider rng, UniformLongSampler.SmallRangeUniformLongSampler source)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
sample()
Creates along
sample.UniformLongSampler
withUniformRandomProvider(UniformRandomProvider rng)
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 Detail
-
n
private final long n
Maximum range of the sample (exclusive).
-
limit
private final long limit
Limit 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 Detail
-
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 Detail
-
sample
public long sample()
Description copied from interface:LongSampler
Creates along
sample.- Returns:
- a sample.
-
withUniformRandomProvider
public UniformLongSampler withUniformRandomProvider(UniformRandomProvider rng)
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
-
-