BTW, I think the clearest remains my generator proposal:
string randomString =
    fastGenerator!(() => letters[uniform(0, $)]).take(9).array;

If the goal was to replace iota(n).map, it may be better to just have something like:

    generate!(() => letters[uniform(0, $)])(n).array

But of course, your fastGenerator is more general. I personally don't often have a need to generate an infinite range in this way, but other people may.

Any chance you could tell me how it fares in your bench?

I used this code:

auto tmp = FastGenerator!(() => letters[uniform(0, $)])().take(n).array;

When I build it with GDC, it performs about the same as the code that uses iota and map. When I build it with DMD it's about 10% slower than the code that uses iota and map. It seems that DMD fails to inline the lambda in this case.

By the way, this is not a very good benchmark for ranges because most of the time is spent generating random numbers.

Reply via email to