dice

fnsize_t dice(Rng, Num)(ref Rng rnd, Num[] proportions...) if (isNumeric!Num && isForwardRange!Rng)

Get a random index into a list of weights corresponding to each index

Similar to rolling a die with relative probabilities stored in proportions. Returns the index in proportions that was chosen.

Note

Usually, dice are 'fair', meaning that each side has equal probability

to come up, in which case 1 + uniform(0, 6) can simply be used. In future Phobos versions, this function might get renamed to something like weightedChoice to avoid confusion.

Parameters

rnd(optional) random number generator to use; if not specified, defaults to rndGen
proportionsforward range or list of individual values whose elements correspond to the probabilities with which to choose the corresponding index value

Returns

Random variate drawn from the index values

[0, ... proportions.length - 1], with the probability of getting an individual index value i being proportional to proportions[i].

fnsize_t dice(R, Range)(ref R rnd, Range proportions) if (isForwardRange!Range && isNumeric!(ElementType!Range) && !isArray!Range)

Ditto

fnsize_t dice(Range)(Range proportions) if (isForwardRange!Range && isNumeric!(ElementType!Range) && !isArray!Range)

Ditto

fnsize_t dice(Num)(Num[] proportions...) if (isNumeric!Num)

Ditto