You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mark (JIRA)" <ji...@apache.org> on 2014/11/02 22:29:33 UTC
[jira] [Created] (MATH-1161) Feature request: shuffle algorithms
for generic types
Mark created MATH-1161:
--------------------------
Summary: Feature request: shuffle algorithms for generic types
Key: MATH-1161
URL: https://issues.apache.org/jira/browse/MATH-1161
Project: Commons Math
Issue Type: Wish
Affects Versions: 3.3
Reporter: Mark
Priority: Minor
The current shuffle algorithm works on int[]. I often need something more generic for arbitrary array types.
Example:
import java.util.Random;
public class Shuffle<T> {
private static final Random rnd = new Random();
// Implementing Fisher–Yates shuffle
public void shuffle(T[] ar) {
for (int i = ar.length - 1; i > 0; i--) {
int index = rnd.nextInt(i + 1);
T a = ar[index];
ar[index] = ar[i];
ar[i] = a;
}
}
}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)