|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.ccg.util.Random
public final class Random
Helper functions to help in the use of java.util.Random.
When working on a simple WordSearch game for my kids, I found that
there were a lot of handy little functions for making use of the
java.util.Random class which were not provided elsewhere. This
class provides some of these functions. There are functions for
getting a random integer within a specified range, or shuffling
(randomizing) the contents of a array, java.util.Vector or
java.lang.String object.
All of the members of this class are static, hence you typically
would not create any objects of this type, but call the member
functions directly instead.
Source code to a com.ccg.example.util.Random example
program which makes use of this class has been provided.
Random| Constructor Summary | |
|---|---|
Random()
|
|
| Method Summary | |
|---|---|
static int |
getLessThan(int range,
Random rng)
Get a random integer value in the range of [0,N-1]. |
static int |
rollDice(int[] dice,
int numSides,
Random rng)
Simulate rolling a number of N sided dice and get the results of each roll. |
static int |
rollDice(int numDice,
int numSides,
Random rng)
Simulate rolling a number of N sided dice. |
static void |
shuffle(Object[] whatToShuffle,
Random rng)
Shuffles the order of the contents of an array. |
static String |
shuffle(String whatToShuffle,
Random rng)
Shuffles the characters in a string. |
static void |
shuffle(Vector whatToShuffle,
Random rng)
Shuffles the order of the contents of an java.util.Vector. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Random()
| Method Detail |
|---|
public static final int getLessThan(int range,
Random rng)
limit - Limit for the returned random number.rng - Random number generator to generate the next integer value
from - the nextInt() member will be used.
Random
public static final String shuffle(String whatToShuffle,
Random rng)
whatToShuffle - Source string to be shuffledrng - Random number generator to generate the next integer value
from - the nextInt() member will be used.
Random,
getLessThan(int, java.util.Random)
public static final void shuffle(Object[] whatToShuffle,
Random rng)
whatToShuffle - Array of objects to shuffle.rng - Random number generator to generate the random indexes for the
results (using the nextInt() member) will be used.Random,
getLessThan(int, java.util.Random)
public static final void shuffle(Vector whatToShuffle,
Random rng)
whatToShuffle - Vector containing the objects to shuffle.rng - Random number generator to generate the random indexes for the
results (using the nextInt() member) will be used.Random,
getLessThan(int, java.util.Random)
public static final int rollDice(int numDice,
int numSides,
Random rng)
numDice - How many dice to rollnumSides - How many sides on each dicerng - Random number generator used to generate each roll.
rollDice(int[],int,java.util.Random),
getLessThan(int, java.util.Random)
public static final int rollDice(int[] dice,
int numSides,
Random rng)
dice - Array to store the value of each die as it is rolled - the
number of dice rolled will be determined by the length of the
array (do not pass NULL).numSides - How many sides on each dicerng - Random number generator used to generate each roll.
rollDice(int,int,java.util.Random),
getLessThan(int, java.util.Random)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||