The OpenD Programming Language

choice

Returns a random, uniformly chosen, element e from the supplied Range range. If no random number generator is passed, the default rndGen is used.

Parameters

range Range

a random access range that has the length property defined

Return Value

Type: auto ref

A single random element drawn from the range. If it can, it will return a ref to the range element, otherwise it will return a copy.

Examples

auto rnd = MinstdRand0(42);

auto elem  = [1, 2, 3, 4, 5].choice(rnd);
version (D_LP64) // https://issues.dlang.org/show_bug.cgi?id=15147
assert(elem == 3);

Meta