Example usage for org.apache.commons.math.random MersenneTwister nextInt

List of usage examples for org.apache.commons.math.random MersenneTwister nextInt

Introduction

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

Prototype

public int nextInt(int n) throws IllegalArgumentException 

Source Link

Usage

From source file:br.upe.ecomp.doss.problem.movingpeaks.MovingPeaks.java

private double[] getMovingVector() {
    MersenneTwister random = new MersenneTwister(System.nanoTime());
    double[] vector = new double[dimensions];
    double movingLengthFraction = movingLength / dimensions;
    List<Integer> indexes = new ArrayList<Integer>();
    for (int i = 0; i < dimensions; i++) {
        indexes.add(i);//from   w  ww  .jav  a  2  s . com
    }

    int index;
    while (indexes.size() > 1) {
        index = indexes.remove(random.nextInt(indexes.size() - 1));
        vector[index] = movingLengthFraction * random.nextDouble();
    }
    vector[indexes.remove(0)] = movingLength - getLength(vector);

    return vector;
}