Package jsl.utilities.random.rvariable
Class ConstantRV
- java.lang.Object
-
- jsl.utilities.random.rvariable.ConstantRV
-
- All Implemented Interfaces:
java.util.function.DoubleSupplier
,GetNameIfc
,GetValueIfc
,IdentityIfc
,PreviousValueIfc
,RandomIfc
,GetRandomNumberStreamIfc
,RNStreamControlIfc
,SetRandomNumberStreamIfc
,NewAntitheticInstanceIfc
,RVariableIfc
,SampleIfc
- Direct Known Subclasses:
VConstantRV
public class ConstantRV extends java.lang.Object implements RVariableIfc, IdentityIfc
Allows a constant to pretend to be a random variable
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jsl.utilities.random.rvariable.RVariableIfc
RVariableIfc.RVType
-
-
Field Summary
Fields Modifier and Type Field Description protected double
myValue
static ConstantRV
ONE
A constant to represent one for sharingstatic ConstantRV
POSITIVE_INFINITY
A constant to represent positive infinity for sharingstatic ConstantRV
TWO
A constant to represent two for sharingstatic ConstantRV
ZERO
A constant to represent zero for sharing
-
Constructor Summary
Constructors Constructor Description ConstantRV(double value)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
advanceToNextSubstream()
Positions the RNG at the beginning of its next substreamboolean
getAntitheticOption()
int
getId()
java.lang.String
getName()
double
getPreviousValue()
Gets the previous number from the sequence of valuesRNStreamIfc
getRandomNumberStream()
static RVControls
makeControls()
The keys are "value", the default value is 1.0RVariableIfc
newAntitheticInstance()
ConstantRV
newInstance()
ConstantRV
newInstance(RNStreamIfc rng)
void
resetStartStream()
The resetStartStream method will position the RNG at the beginning of its stream.void
resetStartSubstream()
Resets the position of the RNG at the start of the current substreamdouble
sample()
void
setAntitheticOption(boolean flag)
Tells the stream to start producing antithetic variatesvoid
setName(java.lang.String str)
Sets the namevoid
setRandomNumberStream(RNStreamIfc stream)
Sets the underlying random number streamjava.lang.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.random.rng.GetRandomNumberStreamIfc
getStreamNumber
-
Methods inherited from interface jsl.utilities.random.rvariable.RVariableIfc
asDoubleStream, getAsDouble, getSumOfValues, getValue
-
Methods inherited from interface jsl.utilities.random.rng.SetRandomNumberStreamIfc
setRandomNumberStream
-
-
-
-
Field Detail
-
ZERO
public static final ConstantRV ZERO
A constant to represent zero for sharing
-
ONE
public static final ConstantRV ONE
A constant to represent one for sharing
-
TWO
public static final ConstantRV TWO
A constant to represent two for sharing
-
POSITIVE_INFINITY
public static final ConstantRV POSITIVE_INFINITY
A constant to represent positive infinity for sharing
-
myValue
protected double myValue
-
-
Method Detail
-
newInstance
public final ConstantRV newInstance(RNStreamIfc rng)
- Specified by:
newInstance
in interfaceRVariableIfc
- Parameters:
rng
- the RNStreamIfc to use- Returns:
- a new instance with same parameter value
-
newInstance
public final ConstantRV newInstance()
- Specified by:
newInstance
in interfaceRVariableIfc
- Returns:
- a new instance with same parameter value
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getName
public final java.lang.String getName()
- Specified by:
getName
in interfaceGetNameIfc
- Returns:
- a string representing the name of the object
-
getId
public final int getId()
- Specified by:
getId
in interfaceIdentityIfc
- Returns:
- an int representing the id of the object
-
setName
public final void setName(java.lang.String str)
Sets the name- Parameters:
str
- The name as a string.
-
sample
public final double sample()
-
resetStartStream
public final void resetStartStream()
Description copied from interface:RNStreamControlIfc
The resetStartStream method will position the RNG at the beginning of its stream. This is the same location in the stream as assigned when the RNG was created and initialized.- Specified by:
resetStartStream
in interfaceRNStreamControlIfc
-
resetStartSubstream
public final void resetStartSubstream()
Description copied from interface:RNStreamControlIfc
Resets the position of the RNG at the start of the current substream- Specified by:
resetStartSubstream
in interfaceRNStreamControlIfc
-
advanceToNextSubstream
public final void advanceToNextSubstream()
Description copied from interface:RNStreamControlIfc
Positions the RNG at the beginning of its next substream- Specified by:
advanceToNextSubstream
in interfaceRNStreamControlIfc
-
setAntitheticOption
public final void setAntitheticOption(boolean flag)
Description copied from interface:RNStreamControlIfc
Tells the stream to start producing antithetic variates- Specified by:
setAntitheticOption
in interfaceRNStreamControlIfc
- Parameters:
flag
- true means that it produces antithetic variates.
-
getAntitheticOption
public final boolean getAntitheticOption()
- Specified by:
getAntitheticOption
in interfaceRNStreamControlIfc
- Returns:
- true means on
-
getPreviousValue
public double getPreviousValue()
Description copied from interface:PreviousValueIfc
Gets the previous number from the sequence of values- Specified by:
getPreviousValue
in interfacePreviousValueIfc
- Returns:
- a double representing the last value in the sequence
-
newAntitheticInstance
public final RVariableIfc newAntitheticInstance()
- Specified by:
newAntitheticInstance
in interfaceNewAntitheticInstanceIfc
- Returns:
- a new instance with same parameter value, but that has antithetic variates
-
makeControls
public static RVControls makeControls()
The keys are "value", the default value is 1.0- Returns:
- a control for Constant random variables
-
getRandomNumberStream
public RNStreamIfc getRandomNumberStream()
- Specified by:
getRandomNumberStream
in interfaceGetRandomNumberStreamIfc
- Returns:
- the random number stream reference
-
setRandomNumberStream
public void setRandomNumberStream(RNStreamIfc stream)
Description copied from interface:SetRandomNumberStreamIfc
Sets the underlying random number stream- Specified by:
setRandomNumberStream
in interfaceSetRandomNumberStreamIfc
- Parameters:
stream
- the reference to the random number stream, must not be null
-
-