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

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

Introduction

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

Prototype

public int nextInt(int lower, int upper) throws NumberIsTooLargeException 

Source Link

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;
            }// w  w w  .j  av  a2  s  .c o m
        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()));
    }
}