Skip to content
Snippets Groups Projects
Commit e4aecc1b authored by Chris Larsen's avatar Chris Larsen
Browse files

[core] Add a Fisher-Yates array shuffle to the Utils class.

parent a12928ec
No related branches found
No related tags found
No related merge requests found
......@@ -226,4 +226,19 @@ public final class Utils {
}
return map;
}
/**
* Simple Fisher-Yates array shuffle to randomize discrete sets.
* @param array The array to randomly shuffle.
* @return The shuffled array.
*/
public static <T> T [] shuffleArray(final T[] array) {
for (int i = array.length -1; i > 0; i--) {
final int idx = RAND.nextInt(i + 1);
final T temp = array[idx];
array[idx] = array[i];
array[i] = temp;
}
return array;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment