You expect that output to contain only 5 stars.

Better seen with this code:


import std.stdio, std.range, std.algorithm, std.traits, std.random;

auto distinct(Range)(Range r) if (isInputRange!Range) {
    bool[ForeachType!Range] mySet;

    return r.filter!((k) {
        if (k in mySet)
            return false;
        mySet[k] = true;
        return true;
    });
}

void main() {
    5.iota.map!((_) {
        auto x = uniform(0, 10);
        write("*");
        return x;
    }).distinct.array;
}


Bye,
bearophile

Reply via email to