On 2/23/13 4:25 PM, Jens Mueller wrote:
auto randomLetter = () => letters[uniform (0, letters.length)];
auto randomString = iota(10).map!(_ => randomLetter()).array();
auto randomString = iota(10).map!(_ => letters[uniform(0, $)]).array;
Bearophile has long asked for a one-parameter uniform(n) that does what
uniform(0, n) does. Perhaps this provides a good supporting argument.
With that enhancement:
auto randomString = iota(10).map!(_ => letters[uniform($)]).array;
I expect this to be fast and only allocate once.
Andrei