public int rouletteWheel(BoundedRandomGenerator<Double> randomGenerator) {
    //Calculate the inverse sum
    double inverseSum = 0.0;
    for (int hypercube : hypercubes) {
      if (hypercube > 0) {
        inverseSum += 1.0 / (double) hypercube;
      }
    }

    //Calculate a random value between 0 and sumaInversa
    double random = randomGenerator.getRandomValue(0.0, inverseSum);
    int hypercube = 0;
    double accumulatedSum = 0.0;
    while (hypercube < hypercubes.length) {
      if (hypercubes[hypercube] > 0) {
        accumulatedSum += 1.0 / (double) hypercubes[hypercube];
      }

      if (accumulatedSum > random) {
        return hypercube;
      }

      hypercube++;
    }

    return hypercube;
  }
public int rouletteWheel ( BoundedRandomGenerator < Double > randomGenerator ) { double inverseSum = 0.0 ; for ( int hypercube : hypercubes ) { if ( hypercube > 0 ) { inverseSum += 1.0 / ( double ) hypercube ; } } double random = randomGenerator . getRandomValue ( 0.0 , inverseSum ) ; int hypercube = 0 ; double accumulatedSum = 0.0 ; while ( hypercube < hypercubes . length ) { if ( hypercubes [ hypercube ] > 0 ) { accumulatedSum += 1.0 / ( double ) hypercubes [ hypercube ] ; } if ( accumulatedSum > random ) { return hypercube ; } hypercube ++ ; } return hypercube ; }
Returns a random hypercube using a rouleteWheel method.

@param randomGenerator the {@link BoundedRandomGenerator} to use for the roulette

@return the number of the selected hypercube.