public class ContinuousUniformSampler extends SamplerBase implements SharedStateContinuousSampler
Sampling uses UniformRandomProvider.nextDouble()
.
Constructor and Description |
---|
ContinuousUniformSampler(UniformRandomProvider rng,
double lo,
double hi) |
Modifier and Type | Method and Description |
---|---|
static SharedStateContinuousSampler |
of(UniformRandomProvider rng,
double lo,
double hi)
Creates a new continuous uniform distribution sampler.
|
static SharedStateContinuousSampler |
of(UniformRandomProvider rng,
double lo,
double hi,
boolean excludeBounds)
Creates a new continuous uniform distribution sampler.
|
double |
sample()
Creates a
double sample. |
String |
toString() |
SharedStateContinuousSampler |
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.
|
nextDouble, nextInt, nextInt, nextLong
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
samples, samples
public ContinuousUniformSampler(UniformRandomProvider rng, double lo, double hi)
rng
- Generator of uniformly distributed random numbers.lo
- Lower bound.hi
- Higher bound.public double sample()
double
sample.sample
in interface ContinuousSampler
public String toString()
toString
in class SamplerBase
public SharedStateContinuousSampler withUniformRandomProvider(UniformRandomProvider rng)
withUniformRandomProvider
in interface SharedStateSampler<SharedStateContinuousSampler>
rng
- Generator of uniformly distributed random numbers.public static SharedStateContinuousSampler of(UniformRandomProvider rng, double lo, double hi)
rng
- Generator of uniformly distributed random numbers.lo
- Lower bound.hi
- Higher bound.public static SharedStateContinuousSampler of(UniformRandomProvider rng, double lo, double hi, boolean excludeBounds)
The bounds can be optionally excluded to sample from the open interval
(lower, upper)
. In this case if the bounds have the same sign the
open interval must contain at least 1 double value between the limits; if the
bounds have opposite signs the open interval must contain at least 2 double values
between the limits excluding -0.0
. Thus the interval (-x,x)
will
raise an exception when x
is Double.MIN_VALUE
.
rng
- Generator of uniformly distributed random numbers.lo
- Lower bound.hi
- Higher bound.excludeBounds
- Set to true
to use the open interval
(lower, upper)
.IllegalArgumentException
- If the open interval is invalid.Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.