Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::random: get same number sequences 32/64 bit?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-01-31 14:16:34


AMDG

Sebastian Mach wrote:
> today I found out that boost::random, at least the combination
>
> boost::mt19937 rng(<seed>);
> typedef boost::uniform_int<int> dist_t;
> dist_t dist (<min>, <max>);
> boost::variate_generator<
> boost::mt19937&,
> dist_t
>
>> rand_ (rng, dist);
>>
>
>
> will give me different results depending on whether I use "g++ (Debian
> 4.3.2-1.1) 4.3.2" (with sizeof(long)=8) or "g++.exe (TDM-2 mingw32)
> 4.4.1" (with sizeof(long)=4).
>
> This testcase:
> ++
> #include <boost/random.hpp>
>
> boost::mt19937 rng(1);
> typedef boost::uniform_int<int> dist_t;
> dist_t dist (0, 16);
> boost::variate_generator<
> boost::mt19937&,
> dist_t
>
>> rand_ (rng, dist);
>>
>
> int main () {
> for (int i=0; i<6; ++i) {
> std::cout << rand_() << std::endl;
> }
> }
> --
>
> will print 16 8 1 6 0 12 with the 64bit variant variant, but 7 16 12
> 15 0 2 with the 32bit variant.
>
> Is there a (preferably portable) way to ensure that they will be the
> same on all 32bit+ machines?
>
> Otherwise this would be a real stopper to use boost::random for me,
> and I'd have to go back to libcoyotl's Mersenne Twister, which gives
> consistent results, upon which I really depend.
>

Are you using the same version of Boost for both?
There were a bunch of bug fixes in uniform_int a few releases
ago, which change the exact sequence produced.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net