Package squidpony.squidmath
Class JavaRNG
java.lang.Object
squidpony.squidmath.JavaRNG
- All Implemented Interfaces:
Serializable
,RandomnessSource
public class JavaRNG extends Object implements RandomnessSource, Serializable
This makes java.util.Random available for testing purposes.
It is relevant mainly as example code, or if you want to
compare what your results would have been without using a
better RNG. Results might not be apparent in some cases,
although the terrible performance of java.util.Random is
likely to be the first thing a user notices if this is
used heavily (i.e. to generate white noise with one call
to
nextDouble()
per cell).- Author:
- Ben McLean
- See Also:
- Serialized Form
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description JavaRNG
copy()
boolean
equals(Object o)
int
hashCode()
int
next(int bits)
boolean
nextBoolean()
Gets a random value, true or false.void
nextBytes(byte[] bytes)
Given a byte array as a parameter, this will fill the array with random bytes (modifying it in-place).double
nextDouble()
double
nextDouble(double outer)
float
nextFloat()
Gets a uniform random float in the range [0.0,1.0)int
nextInt()
int
nextInt(int bound)
int
nextInt(int lower, int upper)
Inclusive lower, exclusive upper.long
nextLong()
String
toString()
-
Field Details
-
Constructor Details
-
Method Details
-
next
- Specified by:
next
in interfaceRandomnessSource
-
nextLong
- Specified by:
nextLong
in interfaceRandomnessSource
-
copy
- Specified by:
copy
in interfaceRandomnessSource
-
nextInt
-
nextInt
-
nextInt
Inclusive lower, exclusive upper.- Parameters:
lower
- the lower bound, inclusive, can be positive or negativeupper
- the upper bound, exclusive, should be positive, must be greater than lower- Returns:
- a random int at least equal to lower and less than upper
-
nextDouble
-
nextDouble
-
nextFloat
Gets a uniform random float in the range [0.0,1.0)- Returns:
- a random float at least equal to 0.0 and less than 1.0
-
nextBoolean
Gets a random value, true or false.- Returns:
- a random true or false value.
-
nextBytes
Given a byte array as a parameter, this will fill the array with random bytes (modifying it in-place). -
toString
-
equals
-
hashCode
-