code: public static RealMatrix shuffleRows (RealMatrix matrix, RandomGenerator randomGenerator) {
          // Create an index vector to be shuffled:
          int[] index = MathArrays.sequence(matrix.getRowDimension(), 0, 1);
          MathArrays.shuffle(index, randomGenerator);
  
          // Create a new matrix:
          RealMatrix retval = MatrixUtils.createRealMatrix(matrix.getRowDimension(), matrix.getColumnDimension());
  
          // Populate:
          for (int row = 0; row < index.length; row++) {
              retval.setRowVector(row, matrix.getRowVector(index[row]));
          }
  
          // Done, return:
          return retval;
      }
docs: Shuffles rows of a matrix using the provided random number generator.
  
  @param matrix The matrix of which the rows will be shuffled.
  @param randomGenerator The random number generator to be used.
  @return The new shuffled matrix.