public class RandomXS128
extends java.util.Random
Random
's, and its cycle length is 2128 − 1, which
is more than enough for any single-thread application. More details and algorithms can be found here.
Instances of RandomXS128 are not thread-safe.
构造器和说明 |
---|
RandomXS128()
Creates a new random number generator.
|
RandomXS128(long seed)
Creates a new random number generator using a single
long seed. |
RandomXS128(long seed0,
long seed1)
Creates a new random number generator using two
long seeds. |
限定符和类型 | 方法和说明 |
---|---|
long |
getState(int seed)
Returns the internal seeds to allow state saving.
|
protected int |
next(int bits)
This protected method is final because, contrary to the superclass, it's not used anymore by the other methods.
|
boolean |
nextBoolean()
Returns a pseudo-random, uniformly distributed
boolean value from this random number generator's sequence. |
void |
nextBytes(byte[] bytes)
Generates random bytes and places them into a user-supplied byte array.
|
double |
nextDouble()
Returns a pseudo-random, uniformly distributed
double value between 0.0 and 1.0 from this random number generator's
sequence. |
float |
nextFloat()
Returns a pseudo-random, uniformly distributed
float value between 0.0 and 1.0 from this random number generator's
sequence. |
int |
nextInt()
Returns the next pseudo-random, uniformly distributed
int value from this random number generator's sequence. |
int |
nextInt(int n)
Returns a pseudo-random, uniformly distributed
int value between 0 (inclusive) and the specified value (exclusive),
drawn from this random number generator's sequence. |
long |
nextLong()
Returns the next pseudo-random, uniformly distributed
long value from this random number generator's sequence. |
long |
nextLong(long n)
Returns a pseudo-random, uniformly distributed
long value between 0 (inclusive) and the specified value (exclusive),
drawn from this random number generator's sequence. |
void |
setSeed(long seed)
Sets the internal seed of this generator based on the given
long value. |
void |
setState(long seed0,
long seed1)
Sets the internal state of this generator.
|
public RandomXS128()
This implementation creates a Random
instance to generate the initial seed.
public RandomXS128(long seed)
long
seed.seed
- the initial seedpublic RandomXS128(long seed0, long seed1)
long
seeds.seed0
- the first part of the initial seedseed1
- the second part of the initial seedpublic long nextLong()
long
value from this random number generator's sequence.
Subclasses should override this, as this is used by all other methods.
nextLong
在类中 java.util.Random
protected final int next(int bits)
next
在类中 java.util.Random
public int nextInt()
int
value from this random number generator's sequence.
This implementation uses nextLong()
internally.
nextInt
在类中 java.util.Random
public int nextInt(int n)
int
value between 0 (inclusive) and the specified value (exclusive),
drawn from this random number generator's sequence.
This implementation uses nextLong()
internally.
nextInt
在类中 java.util.Random
n
- the positive bound on the random number to be returned.int
value between 0
(inclusive) and n
(exclusive).public long nextLong(long n)
long
value between 0 (inclusive) and the specified value (exclusive),
drawn from this random number generator's sequence. The algorithm used to generate the value guarantees that the result is
uniform, provided that the sequence of 64-bit values produced by this generator is.
This implementation uses nextLong()
internally.
n
- the positive bound on the random number to be returned.long
value between 0
(inclusive) and n
(exclusive).public double nextDouble()
double
value between 0.0 and 1.0 from this random number generator's
sequence.
This implementation uses nextLong()
internally.
nextDouble
在类中 java.util.Random
public float nextFloat()
float
value between 0.0 and 1.0 from this random number generator's
sequence.
This implementation uses nextLong()
internally.
nextFloat
在类中 java.util.Random
public boolean nextBoolean()
boolean
value from this random number generator's sequence.
This implementation uses nextLong()
internally.
nextBoolean
在类中 java.util.Random
public void nextBytes(byte[] bytes)
This implementation uses nextLong()
internally.
nextBytes
在类中 java.util.Random
public void setSeed(long seed)
long
value.
The given seed is passed twice through a hash function. This way, if the user passes a small value we avoid the short irregular transient associated with states having a very small number of bits set.
setSeed
在类中 java.util.Random
seed
- a nonzero seed for this generator (if zero, the generator will be seeded with Long.MIN_VALUE
).public void setState(long seed0, long seed1)
seed0
- the first part of the internal stateseed1
- the second part of the internal statepublic long getState(int seed)
seed
- must be 0 or 1, designating which of the 2 long seeds to return