Too complicated code for generating a random string?
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Feb 23 08:25:45 PST 2013
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
More information about the Digitalmars-d
mailing list