Skip to content

Commit

Permalink
[core] Add a Fisher-Yates array shuffle to the Utils class.
Browse files Browse the repository at this point in the history
  • Loading branch information
manolama committed Aug 5, 2017
1 parent a12928e commit e4aecc1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions core/src/main/java/com/yahoo/ycsb/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,19 @@ public static Map<String, Long[]> getGCStatst() {
}
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 comments on commit e4aecc1

Please sign in to comment.