You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Phil Steitz <ph...@gmail.com> on 2013/07/22 05:40:42 UTC

[math] exposing getNatural and shuffle from RandomDataGenerator

I would like to use getNatural and shuffle from RandomDataGenerator
outside of that class (inside [math] I need to efficiently generate
random n-m partitions of {0, ..., n + m - 1}).  I think getNatural
could go into MathArrays and shuffle could just be exposed by
RandomDataGenerator.  Any objections to making these public?  (I
promise to rewrite the javadoc for getNatural so it makes sense to
non-logicians and I would even be OK with renaming it ;)

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] exposing getNatural and shuffle from RandomDataGenerator

Posted by Thomas Neidhart <th...@gmail.com>.
On 07/22/2013 05:40 AM, Phil Steitz wrote:
> I would like to use getNatural and shuffle from RandomDataGenerator
> outside of that class (inside [math] I need to efficiently generate
> random n-m partitions of {0, ..., n + m - 1}).  I think getNatural
> could go into MathArrays and shuffle could just be exposed by
> RandomDataGenerator.  Any objections to making these public?  (I
> promise to rewrite the javadoc for getNatural so it makes sense to
> non-logicians and I would even be OK with renaming it ;)

fyi: in collections there is now also a PermutationIterator for unique
permutations of a given input collection in case you have a need for this.

Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] exposing getNatural and shuffle from RandomDataGenerator

Posted by Phil Steitz <ph...@gmail.com>.
On 7/22/13 12:19 PM, Gilles wrote:
> On Sun, 21 Jul 2013 20:40:42 -0700, Phil Steitz wrote:
>> I would like to use getNatural and shuffle from RandomDataGenerator
>> outside of that class (inside [math] I need to efficiently generate
>> random n-m partitions of {0, ..., n + m - 1}).  I think getNatural
>> could go into MathArrays and shuffle could just be exposed by
>> RandomDataGenerator.  Any objections to making these public?  (I
>> promise to rewrite the javadoc for getNatural so it makes sense to
>> non-logicians and I would even be OK with renaming it ;)
>
> "shuffle" could probably be useful in other contexts too. Various
> versions could also be defined in "MathArrays":
>
> ---CUT---
> public enum Position {
>   /** Designates the beginning of the array (near index 0). */
>   HEAD,
>   /** Designates the end of the array. */
>   TAIL
> }
>
> public static void shuffle(int[] list,
>                            int start,
>                            Position pos,
>                            RandomGenerator rng) {
>   // ...
> }
> ---CUT---
>
> And "double" versions:
>
> ---CUT---
> public static void shuffle(double[] list,
>                            int start,
>                            Position pos,
>                            RandomGenerator rng) {
>   // ...
> }
> ---CUT---
>
> And obvious overloads: e.g.
>
> ---CUT---
> public static void shuffle(double[] list, RandomGenerator rng)
> public static void shuffle(double[] list)
> ---CUT---
>
>
> The method in RandomDataGenerator would become a client:
>
> ---CUT---
> private void shuffle(int[] list, int end) {
>   MathArrays.shuffle(list, MathArrays.Position.TAIL, end,
> getRandomGenerator());
> }
> ---CUT---

+1

 All that I need immediately is the int[] version that shuffles the
entire array, but I agree that the above could prove useful and are
natural.

Phil
>
>
> Regards,
> Gilles
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [math] exposing getNatural and shuffle from RandomDataGenerator

Posted by Gilles <gi...@harfang.homelinux.org>.
On Sun, 21 Jul 2013 20:40:42 -0700, Phil Steitz wrote:
> I would like to use getNatural and shuffle from RandomDataGenerator
> outside of that class (inside [math] I need to efficiently generate
> random n-m partitions of {0, ..., n + m - 1}).  I think getNatural
> could go into MathArrays and shuffle could just be exposed by
> RandomDataGenerator.  Any objections to making these public?  (I
> promise to rewrite the javadoc for getNatural so it makes sense to
> non-logicians and I would even be OK with renaming it ;)

"shuffle" could probably be useful in other contexts too. Various
versions could also be defined in "MathArrays":

---CUT---
public enum Position {
   /** Designates the beginning of the array (near index 0). */
   HEAD,
   /** Designates the end of the array. */
   TAIL
}

public static void shuffle(int[] list,
                            int start,
                            Position pos,
                            RandomGenerator rng) {
   // ...
}
---CUT---

And "double" versions:

---CUT---
public static void shuffle(double[] list,
                            int start,
                            Position pos,
                            RandomGenerator rng) {
   // ...
}
---CUT---

And obvious overloads: e.g.

---CUT---
public static void shuffle(double[] list, RandomGenerator rng)
public static void shuffle(double[] list)
---CUT---


The method in RandomDataGenerator would become a client:

---CUT---
private void shuffle(int[] list, int end) {
   MathArrays.shuffle(list, MathArrays.Position.TAIL, end, 
getRandomGenerator());
}
---CUT---


Regards,
Gilles


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org