Class UniformLongSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.UniformLongSampler
- All Implemented Interfaces:
LongSampler, SharedStateLongSampler, SharedStateSampler<SharedStateLongSampler>
Discrete uniform distribution sampler generating values of type
long.
Sampling uses UniformRandomProvider.nextLong().
When the range is a power of two the number of calls is 1 per sample.
Otherwise a rejection algorithm is used to ensure uniformity. In the worst
case scenario where the range spans half the range of a long
(263 + 1) the expected number of calls is 2 per sample.
- Since:
- 1.4
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final UniformRandomProviderUnderlying source of randomness. -
Method Summary
Modifier and TypeMethodDescriptionstatic UniformLongSamplerof(UniformRandomProvider rng, long lower, long upper) Creates a new discrete uniform distribution sampler.toString()abstract UniformLongSamplerCreate 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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface LongSampler
sample, samples, samples
-
Field Details
-
rng
Underlying source of randomness.
-
-
Method Details
-
toString
-
withUniformRandomProvider
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:
withUniformRandomProviderin interfaceSharedStateSampler<SharedStateLongSampler>- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
Creates a new discrete uniform distribution sampler.- Parameters:
rng- Generator of uniformly distributed random numbers.lower- Lower bound (inclusive) of the distribution.upper- Upper bound (inclusive) of the distribution.- Returns:
- the sampler
- Throws:
IllegalArgumentException- iflower > upper.
-