AMDG On 1/21/2011 1:57 PM, Matthew Gwynne wrote:
The problem we now have is that we don't know how the result of mt19937 is being cast down into the number range we are asking for. As far as I am aware, MT19937 only defines how to get a 32 bit integer, not how to then scale that to say the range 1..10. Is it specified clearly how boost::random_number_generator or boost::uniform_distribution does this?
boost::random_number_generator is implemented using boost::uniform_int and no the algorithm isn't specified. It's considered an implementation detail. If you really want to know the details, the source is in boost/random/uniform_int.hpp. I don't expect the implementation to change again, but no guarantees.
However, we have two questions (open problems):
1) How does boost::variate_generator interact with mt19937, and the distribution? Is this documented somewhere?
In the attached code, it seems we can construct boost::uniform_distribution with any maximum value, and still the number generator returns values outside of that range? Is this really right?
Yes. You don't need to use uniform_int with random_number_generator. You can plug mt19937 directly into random_number_generator.
Thanks! Is the behaviour exactly the same?
It isn't going to be exactly the same. If you use mt19937 directly, then random_number_generator will transform the output of the generator to the desired range. If you use uniform_int, the generator's output will first be transformed to the range that you specified for uniform_int, then again by random_number_generator. The result will still have the correct distribution, but the exact values may be different.
It seems so, but the documentation seems to suggest using boost::uniform_distribution.
Where in the documentation? In Christ, Steven Watanabe