dice

Rolls a random die with relative probabilities stored in proportions. Returns the index in proportions that was chosen.

  1. size_t dice(UniformRNG rng, Num[] proportions)
    size_t
    dice
    (
    UniformRNG
    Num
    )
    (
    UniformRNG rng
    ,)
    if (
    isNumeric!Num &&
    isForwardRange!UniformRNG
    )
  2. size_t dice(UniformRNG rng, Range proportions)
  3. size_t dice(Range proportions)
  4. size_t dice(Num[] proportions)

Examples

auto x = dice(0.5, 0.5);   // x is 0 or 1 in equal proportions
auto y = dice(50, 50);     // y is 0 or 1 in equal proportions
auto z = dice(70, 20, 10); // z is 0 70% of the time, 1 20% of the time,
                           // and 2 10% of the time

The range counterpart of dice is the DiscreteDistribution class.

Note: given an identically-seeded RNG as input, hap.random.distribution._dice will produce different values to std.random._dice.

Meta