Example usage for org.apache.commons.math3.random RandomDataImpl nextPermutation

List of usage examples for org.apache.commons.math3.random RandomDataImpl nextPermutation

Introduction

In this page you can find the example usage for org.apache.commons.math3.random RandomDataImpl nextPermutation.

Prototype

public int[] nextPermutation(int n, int k) throws NotStrictlyPositiveException, NumberIsTooLargeException 

Source Link

Document

Uses a 2-cycle permutation shuffle.

Usage

From source file:cc.redberry.core.combinatorics.IntPriorityPermutationsGeneratorTest.java

@Test
public void test3() {
    final int dimm = 6;
    final int maxPerms = 100;
    RandomDataImpl rd = new RandomDataImpl(new MersenneTwister());
    for (int count = 0; count < 100; ++count) {
        //Generate combinatorics
        int pCount = rd.nextInt(1, maxPerms);
        int[][] permutations = new int[pCount][];
        for (int i = 0; i < pCount; ++i)
            OUTER: while (true) {
                permutations[i] = rd.nextPermutation(dimm, dimm);
                for (int j = 0; j < i; ++j)
                    if (Arrays.equals(permutations[i], permutations[j]))
                        continue OUTER;
                break;
            }//ww  w  .  j a v  a2  s .  c  om
        IntPriorityPermutationsGenerator generator = new IntPriorityPermutationsGenerator(dimm);
        //adding priorities
        for (int i = 0; i < pCount; ++i)
            for (int j = 0; j <= pCount - i; ++j) {
                addPriority(generator, permutations[i]);
                generator.reset();
            }

        for (int i = 0; i < pCount; ++i)
            assertTrue(Arrays.equals(permutations[i], generator.take()));
    }
}