Hacker News new | past | comments | ask | show | jobs | submit login

I'd just call it "from_one_to_six".

I guess if it is really a mystery, you could just always do:

    std::uniform_int_distribution<int>{1, 6}(e);
...and use some typedefs to avoid it being quite so verbose.

I'm not sure I grok the bunch of numbers in a row scenario. Usually in that case I'd imagine you'd want to create a bunch of numbers with a consistent distribution, which is exactly why you have the structure you want. If not, you can always create new distributions in an ad hoc fashion (exactly why it is good that the parameters for a distribution are NOT template parameters). Instantiating distributions isn't costing you anything here. It's just a transient struct with a handful of fields... though if you use it for more than one call, it might somehow be more efficient (doubtful, but conceivable).

In practice, you pretty much always end up with something that holds the engine inside it, and you can always decorate it with methods like:

    int roll_die(){ return std::uniform_int_distribution<int>{1, 6}(e); }
...or alternatively:

    template <typename T>
    T uniform(const T begin, const T end) { return std::uniform_int_distribution<T>{begin, end}(e); }



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: