Class ContinuousUniformSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.SamplerBase
-
- org.apache.commons.rng.sampling.distribution.ContinuousUniformSampler
-
- All Implemented Interfaces:
ContinuousSampler,SharedStateContinuousSampler,SharedStateSampler<SharedStateContinuousSampler>
public class ContinuousUniformSampler extends SamplerBase implements SharedStateContinuousSampler
Sampling from a uniform distribution.Sampling uses
UniformRandomProvider.nextDouble().- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description ContinuousUniformSampler(UniformRandomProvider rng, double lo, double hi)Create an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SharedStateContinuousSamplerof(UniformRandomProvider rng, double lo, double hi)Creates a new continuous uniform distribution sampler.static SharedStateContinuousSamplerof(UniformRandomProvider rng, double lo, double hi, boolean excludeBounds)Creates a new continuous uniform distribution sampler.doublesample()Creates adoublesample.StringtoString()SharedStateContinuousSamplerwithUniformRandomProvider(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.SamplerBase
nextDouble, nextInt, nextInt, nextLong
-
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.ContinuousSampler
samples, samples
-
-
-
-
Constructor Detail
-
ContinuousUniformSampler
public ContinuousUniformSampler(UniformRandomProvider rng, double lo, double hi)
Create an instance.- Parameters:
rng- Generator of uniformly distributed random numbers.lo- Lower bound.hi- Higher bound.
-
-
Method Detail
-
sample
public double sample()
Creates adoublesample.- Specified by:
samplein interfaceContinuousSampler- Returns:
- a sample.
-
toString
public String toString()
- Overrides:
toStringin classSamplerBase
-
withUniformRandomProvider
public 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.- Specified by:
withUniformRandomProviderin interfaceSharedStateSampler<SharedStateContinuousSampler>- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-
of
public static SharedStateContinuousSampler of(UniformRandomProvider rng, double lo, double hi)
Creates a new continuous uniform distribution sampler.- Parameters:
rng- Generator of uniformly distributed random numbers.lo- Lower bound.hi- Higher bound.- Returns:
- the sampler
- Since:
- 1.3
-
of
public static SharedStateContinuousSampler of(UniformRandomProvider rng, double lo, double hi, boolean excludeBounds)
Creates a new continuous uniform distribution sampler.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 whenxisDouble.MIN_VALUE.- Parameters:
rng- Generator of uniformly distributed random numbers.lo- Lower bound.hi- Higher bound.excludeBounds- Set totrueto use the open interval(lower, upper).- Returns:
- the sampler
- Throws:
IllegalArgumentException- If the open interval is invalid.- Since:
- 1.4
-
-