Hi,
Is uniform_int_distribution really trivial?
It's relatively trivial. ;)
When I'm writing code that needs both speed and cross-platform behavior, I just do `g() % n`; for most applications the bias of "%" is lost in the noise.
If you need absolute fairness, it'd be like
int mask = std::bit_ceil(n) - 1;
while (true) {
int r = g() & mask;
if (r < n) return r;
}
And if you want your code to work with URBG types `G` where `G::min() != 0` and/or `G::max()+1 < n`, then it'd be like
std::independent_bits_engine<G, 64, uint64_t> realg(g);
and then work with `realg`.
I'm like 90% sure std::independent_bits_engine's behavior is cross-platform, so you wouldn't have to reimplement it.
Actually, if your `G::max()` is too small, it's certainly a better idea to reimplement your `G`, instead of trying to adapt a bad `G` via standard tools.
–Arthur