uniform

Generates a number between a and b. The boundaries parameter controls the shape of the interval (open vs. closed on either side). Valid values for boundaries are "[]", "$(LPAREN)]", "[$(RPAREN)", and "()". The default interval is closed to the left and open to the right. If no random number generator is specified, the default rndGen will be used as the source of randomness.

  1. auto uniform(T1 a, T2 b)
  2. auto uniform(T1 a, T2 b, UniformRNG rng)
  3. auto uniform(T1 a, T2 b, UniformRNG rng)
    uniform
    (
    string boundaries = "[)"
    T1
    T2
    UniformRNG
    )
    (
    T1 a
    ,
    T2 b
    ,
    UniformRNG rng
    )
    if (
    (
    isIntegral!(CommonType!(T1, T2)) ||
    isSomeChar!(CommonType!(T1, T2))
    )
    &&
    isUniformRNG!UniformRNG
    )
    out (result) { static if (boundaries[0] == '(') { assert (a < result); } else { assert (a <= result); } static if (boundaries[1] == ']') { assert (result <= b); } else { assert (result < b); } }
  4. auto uniform(UniformRNG rng)
  5. auto uniform()
  6. auto uniform(UniformRNG rng)
  7. auto uniform()

Examples

auto gen = Random(unpredictableSeed);
// Generate an integer in [0, 1023]
auto a = uniform(0, 1024, gen);
// Generate a float in [0, 1$(RPAREN)
auto a = uniform(0.0f, 1.0f, gen);

Meta