Object[] choose(double P[], double D[][], double F[][], int Rank[], int n) {
        double sP[] = new double[P.length];
        double sum = 0;
        int counter = 0;
        int Selected[] = new int[n];
        double S1[][] = new double[n][D[0].length];
        double F1[][] = new double[n][F[0].length];
        int R1[] = new int[n];

        for (int i = 0; i < P.length; i++) {
            sP[i] = (sum += P[i]);
        }

        while (counter < n) {
            double U;
            int R = -1;
            boolean multipleOccurrences = false;
            do {
                multipleOccurrences = false;
                // Draw random number U between 0 and 1 using a uniform distribution
                U = random(); //generator.nextDouble();
                // Combine labelled U with trapezoidal probability
                for (int i = 0; i < P.length; i++) {
                    if (U < sP[i]) {
                        R = i;
                        break;
                    }
                }
                for (int i = 0; i < counter; i++) {
                    if (Selected[i] == R) {
                        multipleOccurrences = true;
                        break;
                    }
                }
            } while (multipleOccurrences == true);

            Selected[counter] = R;
            for (int j = 0; j < D[0].length; j++) {
                S1[counter][j] = D[R][j];
            }
            for (int j = 0; j < F[0].length; j++) {
                F1[counter][j] = F[R][j];
            }
            R1[counter] = Rank[R];
            counter++;
        }
        return new Object[]{S1, F1, R1};
    }