Randomizerpublic class Randomizer extends Object This class defines methods for computing pseudo-random numbers, and it defines
the state variable that needs to be maintained for use by those methods. |
Fields Summary |
---|
static final int | m | static final int | a | static final int | c | long | seed |
Constructors Summary |
---|
public Randomizer(long seed)The constructor for the Randomizer() class. It must be passed some
arbitrary initial value or "seed" for its pseudo-randomness.
this.seed = seed;
|
Methods Summary |
---|
public float | randomFloat()This method computes a pseudo-random number between 0 and 1 using a very
simple algorithm. Math.random() and java.util.Random are actually a lot
better at computing randomness.
seed = (seed * a + c) % m;
return (float)seed/(float)m;
| public int | randomInt(int max)This method computes a pseudo-random integer between 0 and specified
maximum. It uses randomFloat() above.
return Math.round(max * randomFloat());
|
|