Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In need of a deterministic uniform distribution using C++11

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?

like image 522
bsdunx Avatar asked Jan 20 '26 11:01

bsdunx


1 Answers

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.

like image 145
Howard Hinnant Avatar answered Jan 22 '26 01:01

Howard Hinnant