commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Neidhart (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (MATH-1161) Feature request: shuffle algorithms for generic types
Date Wed, 25 Feb 2015 20:49:06 GMT

     [ https://issues.apache.org/jira/browse/MATH-1161?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Thomas Neidhart resolved MATH-1161.
-----------------------------------
    Resolution: Won't Fix

As this can be achieved with a one-liner, no need to add this to commons-math.

> 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:
> {code}
> 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;
>         }
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message