The OpenD Programming Language

uniform

Generates a uniformly-distributed number in the range [T.min, T.max] for any integral or character type T. If no random number generator is passed, uses the default rndGen.

If an enum is used as type, the random variate is drawn with equal probability from any of the possible values of the enum E.

  1. auto uniform(T1 a, T2 b)
  2. auto uniform(T1 a, T2 b, UniformRandomNumberGenerator urng)
  3. auto uniform(UniformRandomNumberGenerator urng)
  4. auto uniform()
  5. auto uniform(UniformRandomNumberGenerator urng)
    uniform
    (
    E
    UniformRandomNumberGenerator
    )
    (
    ref UniformRandomNumberGenerator urng
    )
    if (
    is(E == enum) &&
    isUniformRNG!UniformRandomNumberGenerator
    )
  6. auto uniform()

Parameters

urng UniformRandomNumberGenerator

(optional) random number generator to use; if not specified, defaults to rndGen

Return Value

Type: auto

Random variate drawn from the uniform distribution across all possible values of the integral, character or enum type T.

Examples

auto rnd = MinstdRand0(42);

assert(rnd.uniform!ubyte == 102);
assert(rnd.uniform!ulong == 4838462006927449017);

enum Fruit { apple, mango, pear }
version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147
assert(rnd.uniform!Fruit == Fruit.mango);

Meta