RestorableUniformRandomProvider
, UniformRandomProvider
IntProvider
, LongProvider
public abstract class BaseProvider extends java.lang.Object implements RestorableUniformRandomProvider
Constructor | Description |
---|---|
BaseProvider() |
Modifier and Type | Method | Description |
---|---|---|
protected void |
checkIndex(int min,
int max,
int index) |
Checks whether
index is in the range [min, max] . |
protected void |
checkStateSize(byte[] state,
int expected) |
Deprecated.
Method is used internally and should be made private in
some future release.
|
protected byte[] |
composeStateInternal(byte[] state,
byte[] parentState) |
Combine parent and subclass states.
|
protected void |
fillState(int[] state,
int[] seed) |
Simple filling procedure.
|
protected void |
fillState(long[] state,
long[] seed) |
Simple filling procedure.
|
protected byte[] |
getStateInternal() |
Creates a snapshot of the RNG state.
|
int |
nextInt(int n) |
|
long |
nextLong(long n) |
|
void |
restoreState(RandomProviderState state) |
|
RandomProviderState |
saveState() |
|
protected void |
setStateInternal(byte[] state) |
Resets the RNG to the given
state . |
protected byte[][] |
splitStateInternal(byte[] state,
int localStateLength) |
Splits the given
state into a part to be consumed by the caller
in order to restore its local state, while the reminder is passed to
the parent class. |
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
nextBoolean, nextBytes, nextBytes, nextDouble, nextFloat, nextInt, nextLong
public BaseProvider()
public int nextInt(int n)
nextInt
in interface UniformRandomProvider
public long nextLong(long n)
nextLong
in interface UniformRandomProvider
public RandomProviderState saveState()
saveState
in interface RestorableUniformRandomProvider
public void restoreState(RandomProviderState state)
restoreState
in interface RestorableUniformRandomProvider
public java.lang.String toString()
toString
in class java.lang.Object
protected byte[] composeStateInternal(byte[] state, byte[] parentState)
getStateInternal()
,
will end with a statement like the following:
return composeStateInternal(state,
super.getStateInternal());
where state
is the state needed and defined by the class
where the method is overridden.state
- State of the calling class.parentState
- State of the calling class' parent.protected byte[][] splitStateInternal(byte[] state, int localStateLength)
state
into a part to be consumed by the caller
in order to restore its local state, while the reminder is passed to
the parent class.
I.e. the body of the overridden setStateInternal(byte[])
,
will contain statements like the following:
final byte[][] s = splitState(state, localStateLength);
// Use "s[0]" to recover the local state.
super.setStateInternal(s[1]);
where state
is the combined state of the calling class and of
all its parents.state
- State.
The local state must be stored at the beginning of the array.localStateLength
- Number of elements that will be consumed by the
locally defined state.java.lang.IllegalStateException
- if state.length < localStateLength
.protected byte[] getStateInternal()
protected void setStateInternal(byte[] state)
state
.state
- State (previously obtained by a call to
getStateInternal()
).java.lang.IllegalStateException
- if the size of the given array is
not consistent with the state defined by this class.checkStateSize(byte[],int)
protected void fillState(int[] state, int[] seed)
state
by copying
min(seed.length, state.length)
elements from
seed
,
state
with non-zero
values (even if seed.length < state.length
).
state
- State. Must be allocated.seed
- Seed. Cannot be null.protected void fillState(long[] state, long[] seed)
state
by copying
min(seed.length, state.length)
elements from
seed
,
state
with non-zero
values (even if seed.length < state.length
).
state
- State. Must be allocated.seed
- Seed. Cannot be null.@Deprecated protected void checkStateSize(byte[] state, int expected)
state
has the expected
size.state
- State.expected
- Expected length of state
array.java.lang.IllegalStateException
- if state.length < expected
.protected void checkIndex(int min, int max, int index)
index
is in the range [min, max]
.min
- Lower bound.max
- Upper bound.index
- Value that must lie within the [min, max]
interval.java.lang.IndexOutOfBoundsException
- if index
is not within the
[min, max]
interval.Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.