public class Random
extends java.lang.Object
Here's a sample of how to use the Random class:
Random r = new Random(0x1234); // the use of the same key is sometimes desirable for (...) { int nextRandomInt = r.between(0,10); char nextRandomChar = r.between('a','z'); ... }
Constructor and Description |
---|
Random()
Randomizes based on the current timestamp
|
Random(int _seed)
The only reasonable seeds are between 0 and 2^31 inclusive; if
you're negative, it'll get the absolute value of it.
|
Modifier and Type | Method and Description |
---|---|
char |
between(char s,
char e)
Returns a random character between the given region.
|
int |
between(int s,
int e)
Returns random integer in the given region.
|
int |
getSeed()
Returns the first seed used
|
protected int |
next(int bits)
Bits should be <= 31
|
double |
nextDouble()
Returns a double floating-point value in the half-open range [0,1).
|
int |
nextInt(int n)
Returns an integer in the range [0,n).
|
public Random(int _seed)
public Random()
protected int next(int bits)
public double nextDouble()
public int nextInt(int n)
between(char, char)
,
between(int, int)
public char between(char s, char e)
s
- the start character in the rangee
- the ending character in the rangepublic int between(int s, int e)
s
- the start number in the rangee
- the ending number in the rangepublic int getSeed()