Return the best solution between those passed as arguments. If they are equal or incomparable
one of them is chosen randomly.

@param randomGenerator {@link RandomGenerator} for the equality case
@return The best solution
971473
public static <S extends Solution<?>> S getBestSolution(S solution1, S solution2, Comparator<S> comparator, RandomGenerator<Double> randomGenerator) {
    return getBestSolution(solution1, solution2, comparator, (a, b) -> randomGenerator.getRandomValue() < 0.5 ? a : b);
  }
366401
public static void foreachRandomInt(int streamSize, Random random,
            int exclusiveBound, IntConsumer eachRandomIntConsumer) {
        foreachRandomInt(streamSize, () -> random.nextInt(exclusiveBound),
                eachRandomIntConsumer);
    }
944237
private function getDefaultGenerator()
    {
        foreach (self::$defaultGenerators as $generator) {
            /** @var Generator\Generator $generator */
            $generator = new $generator();

            if ($generator->isSupported()) {
                return $generator;
            }
        }

        throw new GeneratorException('Default secure random byte generators are not supported by the system');
    }
792301
public static <T> /* @Nullable */ T random(final @NonNull Iterable<T> iterable) {
    return random(RANDOM, iterable);
  }
897028
@Override
    public Randomizer<?> getRandomizer(Field field) {
        if (field.isAnnotationPresent(org.jeasy.random.annotation.Randomizer.class)) {
            org.jeasy.random.annotation.Randomizer randomizer = field.getAnnotation(org.jeasy.random.annotation.Randomizer.class);
            Class<?> type = randomizer.value();
            RandomizerArgument[] arguments = randomizer.args();
            return ReflectionUtils.newInstance(type, arguments);
        }
        return null;
    }
813623
public T[] generateRandomCandidate(Random rng)
    {
        T[] candidate = elements.clone();
        List<T> list = Arrays.asList(candidate);
        Collections.shuffle(list, rng);
        return list.toArray(candidate);
    }
1271839
public static <T> Constructor<T> bestConstructor(Class<T> clazz, Class<?>[] argTypes) throws AmbiguousConstructorMatchException {
        return bestConstructor(collectConstructors(clazz), argTypes);
    }
394517
public static double uniform(Random rng, double min, double max) {
        return rng.nextDouble() * (max - min) + min;
    }
657810
public B getMostProbableOutcome(A first) {
    B best = null;
    double probability = -1.0;
    for (B second : getValues(first)) {
      if (getProbability(first, second) > probability) {
        probability = getProbability(first, second);
        best = second;
      }
    }
    return best;
  }
1321250
public static RandomIter getRandomIterator( GridCoverage2D coverage ) {
        if (coverage instanceof GrassLegacyGridCoverage2D) {
            GrassLegacyGridCoverage2D grassGC = (GrassLegacyGridCoverage2D) coverage;
            GrassLegacyRandomIter iter = new GrassLegacyRandomIter(grassGC.getData());
            return iter;
        }
        RenderedImage renderedImage = coverage.getRenderedImage();
        RandomIter iter = RandomIterFactory.create(renderedImage, null);
        return iter;
    }
501595
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;
  }
1300159
public static int randomIntLessThan(int maxExclusive) {
    checkArgument(
        maxExclusive > Integer.MIN_VALUE, "Cannot produce int less than %s", Integer.MIN_VALUE);
    return randomInt(Integer.MIN_VALUE, maxExclusive);
  }
835913
def random_chain(generators):
    
    while generators:
        g = random.choice(generators)
        try:
            v = g.next()
            if v is None:
                continue
            yield v
        except StopIteration:
            generators.remove(g)
975873
public static <T> Iterator<T> getRandomIterator (Iterator<T> itr)
    {
        ArrayList<T> list = new ArrayList<T>();
        CollectionUtil.addAll(list, itr);
        java.util.Collections.shuffle(list);
        return getUnmodifiableIterator(list);
    }
652700
@SuppressWarnings("unchecked")
  public S execute(S solution) {
    int best;
    evaluations = 0;
    numberOfNonComparableSolutions = 0;

    int rounds = improvementRounds;

    int i = 0;
    while (i < rounds) {
      S mutatedSolution = mutationOperator.execute((S) solution.copy());

      problem.evaluate(mutatedSolution);
      evaluations++;
      if (problem.getNumberOfConstraints() > 0) {
        best = constraintComparator.compare(mutatedSolution, solution);
        if (best == 0) {
          best = comparator.compare(mutatedSolution, solution);
        }
      } else {
        best = comparator.compare(mutatedSolution, solution);
      }

      if (best == -1) {
        solution = mutatedSolution;
        numberOfImprovements++;
      } else if (best == 1) {
        // Current solution is best
      } else {
        numberOfNonComparableSolutions++;

        if (randomGenerator.getRandomValue() < 0.5) {
          solution = mutatedSolution;
        }
      }
      i++;
    }
    return (S) solution.copy();
  }
160313
def random_real_solution(solution_size, lower_bounds, upper_bounds):
    """"""
    return [
        random.uniform(lower_bounds[i], upper_bounds[i])
        for i in range(solution_size)
    ]
1370983
@Override
    public StreamT<W,T> shuffle(final Random random) {

        return (StreamT<W,T>) FoldableTransformerSeq.super.shuffle(random);
    }