|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mindprod.common11.Shuffle
public class Shuffle
Shuffles an int[], much like Collections.shuffle.
Constructor Summary | |
---|---|
Shuffle()
|
Method Summary | |
---|---|
static void |
main(java.lang.String[] args)
test driver demonstrate use of shuffle. |
static void |
shuffle(int[] toShuffle)
Shuffle an array whene Collections.shuffle is not available or where you need high quality randomness. |
static void |
shuffle(int[] toShuffle,
java.util.Random wheel)
This method uses the same technique as Collections.shuffle, but is somewhat simpler with direct array access. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Shuffle()
Method Detail |
---|
public static void shuffle(int[] toShuffle)
The hedge "approximately" is used in the foregoing description because default source of randomness is only approximately an unbiased source of independently chosen bits. If it were a perfect source of randomly chosen bits, then the algorithm would choose permutations with perfect uniformity.
This implementation traverses the list backwards, from the last element up to the second, repeatedly swapping a randomly selected element into the "current position". Elements are randomly selected from the portion of the list that runs from the first element to the current position, inclusive.
toShuffle
- the array to be shuffled.public static void shuffle(int[] toShuffle, java.util.Random wheel)
This implementation traverses the array backwards, from the last element up to the second, repeatedly swapping a randomly selected element into the "current position". Elements are randomly selected from the portion of the list that runs from the first element to the current position, inclusive.
toShuffle
- the array to be shuffled.wheel
- the source of randomness to use to shuffle the list.public static void main(java.lang.String[] args)
args
- not used.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |