Package org.javarosa.xform.parse
Class FisherYates
java.lang.Object
org.javarosa.xform.parse.FisherYates
public class FisherYates extends Object
This class implements the Fisher-Yates
list shuffling algorithm.
Combined with the ParkMiller Random Number Generator
implementation on this library, cross-platform reproducible results
can be guaranteed.
Verified compatible libraries are:
Using other libraries won't guarantee reproducible results.
The main difference between this implementation and the native
Collections.shuffle(java.util.List<?>) consist on the way this one
selects which elements to swap on each iteration. See inlined comments
for more information.
-
Constructor Summary
Constructors Constructor Description FisherYates() -
Method Summary
Modifier and Type Method Description static <T> List<T>shuffle(List<T> input)Shuffle the input list of elements using aRandomRandom Number Generator instance to decide which positions get swapped on each iteration.static <T> List<T>shuffle(List<T> input, long seed)Shuffle the input list of elements using aParkMillerRandom Number Generator instance to decide which positions get swapped on each iteration.static <T> List<T>shuffle(List<T> input, Random random)Shuffle the input list of elements using aRandomRandom Number Generator instance to decide which positions get swapped on each iteration.
-
Constructor Details
-
FisherYates
public FisherYates()
-
-
Method Details
-
shuffle
Shuffle the input list of elements using aRandomRandom Number Generator instance to decide which positions get swapped on each iteration. -
shuffle
Shuffle the input list of elements using aParkMillerRandom Number Generator instance to decide which positions get swapped on each iteration.Use the same seed for the RNGs when reproducible results are required.
-
shuffle
Shuffle the input list of elements using aRandomRandom Number Generator instance to decide which positions get swapped on each iteration.Use the same seed for the RNGs when reproducible results are required. Warning: It's recommended to use
shuffle(List, long)instead, to ensure you are using a cross-platform RNG likeParkMiller.
-