I'm using C++11's random library for producing deterministic random values, I need to restrict the output to various ranges and naturally used std::uniform_int_distribution but much to my dismay the specification gives library implementations too much freedom and output differs between i.e. X86-64 Linux and X86 Windows 7.
Is there any option besides implementing my own distribution to ensure that the output is deterministic regardless of library implementation?
Is there any option besides implementing my own distribution to ensure that the output is deterministic regardless of library implementation?
There is no option besides implementing your own distribution to ensure that the output is deterministic regardless of library implementation. While engines are deterministic, distributions are not.
Typical implementations for uniform_int_distribution will involve "rejection" algorithms which will repeatedly get a number from a URNG and if that result is not in the desired range, throw it away and try again. Variations on that theme will optimize that algorithm by folding out of range values into in-range values so as to minimize rejections without biasing the acceptance range, as the simplistic offset + lcg() % range algorithm does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With