<random>: Prevent full-width shifts in independent_bits_engine by MattStephanson · Pull Request #5740 · microsoft/STL (original) (raw)

It's perfectly stable, so long as tha don't shift it about too much....

—Thomas Pynchon, Mason & Dixon

Fixes #5719.

The second loop in operator() is fine because it's only executed if multiple random values are needed (modulo the rejection sampling), i.e., _Nx > 1. In such cases, _Wx0 <= _Wx / _Nx <= sizeof(_Eres)*8 / 2, so _Wx0+1 < sizeof(_Eres)*8 as long as _Eres is more than two bits.