Too complicated code for generating a random string?

Jens Mueller jens.k.mueller at gmx.de
Sat Feb 23 05:45:45 PST 2013


bearophile wrote:
> Jens Mueller:
> 
> >Which makes me think Phobos is convenient enough in this use case.
> 
> I don't agree. This is not quite worse
> auto randomLetter = () => randomSample(letters, 1,
> letters.length).front;
> 
> than:
> auto randomLetter = () => letters.choice;

Then add choice explicitly.
auto choice(R)(R r) { return randomSample(r, 1, r.length).front; };

The point is that choice is a one-liner when using randomSample. It's a
special case of randomSample. But you may argue that the use case occurs
that often that it should be added. Don't know whether this is the case.

Jens


More information about the Digitalmars-d mailing list