Returns a target-total bounded distribution sample.

@param target The target total value.
@param lower Lower limits.
@param upper Upper limits.
@param randomGenerator The random generator.
@return A vector of target-total bounded sample.
506342
private static double[] _ttbdInner (double target, double[] lower, double[] upper, RandomGenerator randomGenerator) {
        // Initialize the return value:
        final double[] retval = new double[lower.length];

        // Iterate over the retval and simulate:
        for (int i = 0; i < retval.length; i++) {
            if (lower[i] == upper[i]) {
                retval[i] = lower[i];
            }
            else {
                retval[i] = new UniformRealDistribution(randomGenerator, lower[i], upper[i]).sample();
            }
        }

        // Compute the gap of simulated total and target total:
        double gap = target - DMatrixUtils.sum(retval);

        // Iterate over the return values and adjust as per gap:
        for (int i = 0; i < retval.length; i++) {
            // If there is no gap, return the retval:
            if (gap == 0.0) {
                return retval;
            }

            // Calculate the distances to limits:
            final double distanceToLower = lower[i] - retval[i];
            final double distanceToUpper = upper[i] - retval[i];

            // Compute the permissible shift:
            final double shift = gap > 0 ? Math.min(distanceToUpper, gap) : Math.max(distanceToLower, gap);

            // Apply the shift:
            retval[i] += shift;

            // Update gap:
            gap -= shift;
        }

        // Done, return:
        return retval;
    }
19147
public static int getBoundedNumber(Random random, int inclusiveLowerBound,
            int exclusiveUpperBound) {
        return random.nextInt(exclusiveUpperBound - inclusiveLowerBound) +
                inclusiveLowerBound;
    }
1009290
public static BigDecimal sum(final Iterable<? extends Number> target) {
        Validate.notNull(target, "Cannot aggregate on null");
        Validate.containsNoNulls(target, "Cannot aggregate on iterable containing nulls");
        BigDecimal total = BigDecimal.ZERO;
        int size = 0;
        for (final Number element : target) {
            total = total.add(toBigDecimal(element));
            size++;
        }
        if (size == 0) {
            return null;
        }
        return total;
    }
1163728
public static int sampleFromDistribution(double[] d, Random random) {
    // sample from the uniform [0,1]
    double r = random.nextDouble();
    // now compare its value to cumulative values to find what interval it falls in
    double total = 0;
    for (int i = 0; i < d.length - 1; i++) {
      if (Double.isNaN(d[i])) {
        throw new RuntimeException("Can't sample from NaN");
      }
      total += d[i];
      if (r < total) {
        return i;
      }
    }
    return d.length - 1; // in case the "double-math" didn't total to exactly 1.0
  }
927196
public Range<T> open(T lower, T upper) {
        return new DenseRange<T>(sequencer, comparator, Endpoint.Exclude, lower, Optional.of(upper), Endpoint.Exclude);
    }
732344
public static <T> Level0ArrayOperator<Float[],Float> onArray(final Float[] target) {
        return onArrayOf(Types.FLOAT, target);
    }
915767
def uniform(low, high, random_state):
    '''
    
    '''
    assert high > low, 'Upper bound must be larger than lower bound'
    return random_state.uniform(low, high)
1118266
public UpdatableSketchBuilder<U, S> setSamplingProbability(final float samplingProbability) {
    if ((samplingProbability < 0) || (samplingProbability > 1f)) {
      throw new SketchesArgumentException("sampling probability must be between 0 and 1");
    }
    samplingProbability_ = samplingProbability;
    return this;
  }
174989
@Pure
	@Inline(value = "StochasticGenerator.generateRandomValue(new UniformStochasticLaw(($1), ($2)))",
			imported = {StochasticGenerator.class, UniformStochasticLaw.class})
	public static double random(double minX, double maxX) throws MathException {
		return StochasticGenerator.generateRandomValue(new UniformStochasticLaw(minX, maxX));
	}
615859
public static int getRandomInteger(int min, int max) {
		Random r = new Random();
		return r.nextInt(max - min + 1) + min;
	}
504033
@Override
    public INDArray rand(int[] shape, float min, float max, org.nd4j.linalg.api.rng.Random rng) {
        //ensure shapes that wind up being scalar end up with the write shape
        if (shape.length == 1 && shape[0] == 0) {
            shape = new int[] {1, 1};
        }
        return Nd4j.getDistributions().createUniform(min, max).sample(shape);
    }
524872
public function rand($lower = null, $upper = null)
    {
        if ($lower === null && $upper === null) {
            return $this->source->extractNumber();
        }

        if ($lower > $upper) {
            list($lower, $upper) = [$upper, $lower];
        }
        $delta = $upper - $lower;
        $divisor = ($this->source->max()) / ($delta + 1);

        do {
            $retval = (int) floor($this->source->extractNumber() / $divisor);
        } while ($retval > $delta);

        return $retval + $lower;
    }
1208084
public double repairSolutionVariableValue(double value, double lowerBound, double upperBound) {
    if (lowerBound > upperBound) {
      throw new JMetalException("The lower bound (" + lowerBound + ") is greater than the "
          + "upper bound (" + upperBound+")") ;
    }

    double result = value ;
    if (value < lowerBound) {
      result = lowerBound ;
    }
    if (value > upperBound) {
      result = upperBound ;
    }

    return result ;
  }
126338
@SuppressWarnings("unchecked")
    public static <T> Randomizer<T> asRandomizer(final Supplier<T> supplier) {

        class RandomizerProxy implements InvocationHandler {

            private final Supplier<?> target;

            private RandomizerProxy(final Supplier<?> target) {
                this.target = target;
            }

            @Override
            public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
                if ("getRandomValue".equals(method.getName())) {
                    Method getMethod = target.getClass().getMethod("get");
                    getMethod.setAccessible(true);
                    return getMethod.invoke(target);
                }
                return null;
            }
        }

        return (Randomizer<T>) Proxy.newProxyInstance(
                Randomizer.class.getClassLoader(),
                new Class[]{Randomizer.class},
                new RandomizerProxy(supplier));
    }
95930
public static int randomIntGreaterThan(int minExclusive) {
    checkArgument(
        minExclusive < Integer.MAX_VALUE, "Cannot produce int greater than %s", Integer.MAX_VALUE);
    return randomInt(minExclusive + 1, Integer.MAX_VALUE);
  }
1304263
@SuppressWarnings("unchecked")
  // This is not good code, but what's there to be done? TODO
  public static <T> T sample(Counter<T> c, Random rand) {
    Iterable<T> objects;
    Set<T> keySet = c.keySet();
    objects = c.keySet();
    if (rand == null) {
      rand = new Random();
    } else { // TODO: Seems like there should be a way to directly check if T is
             // comparable
      if (!keySet.isEmpty() && keySet.iterator().next() instanceof Comparable) {
        List l = new ArrayList<T>(keySet);
        Collections.sort(l);
        objects = l;
      } else {
        throw new RuntimeException("Results won't be stable since Counters keys are comparable.");
      }
    }
    double r = rand.nextDouble() * c.totalCount();
    double total = 0.0;

    for (T t : objects) { // arbitrary ordering
      total += c.getCount(t);
      if (total >= r)
        return t;
    }
    // only chance of reaching here is if c isn't properly normalized, or if
    // double math makes total<1.0
    return c.keySet().iterator().next();
  }
1002639
public DenseVector sampleVec(int numSamples, Random rand)
    {
        return DenseVector.toDenseVec(sample(numSamples, rand));
    }