Boost logo

Boost :

Subject: Re: [boost] Random numbers question
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-07-24 19:39:40


AMDG

Anant Rao wrote:
> I'm using Mersenne Twister algo to generate random numbers on Windows and Linux using the same code. Boost ver 1.39.
>
> Here's the simple code I have:
>
> boost::mt19937 rng(43);
> boost::uniform_01<boost::mt19937> zeroone(rng);
>
> float randomNumber = zeroone();
>
>
> If I run it multiple times, I get the same result on the same OS, as expected. However, the random numebrs are different between Windows and Linux.
>
> Is this the expected behavior? Is there anything I can do to get the same random numbers on Windowd and Linux?
>

Can you post complete code along with the output.
I get the same results from msvc and gcc from this program.

#include <boost/random/uniform_01.hpp>
#include <boost/random/mersenne_twister.hpp>

int main() {
    boost::mt19937 rng(43);
    boost::uniform_01<boost::mt19937> zeroone(rng);

    for(int i = 0; i < 10; ++i) {
        float randomNumber = zeroone();
        std::cout << randomNumber << std::endl;
    }
}

0.115055
0.496861
0.609067
0.102915
0.133391
0.148773
0.24059
0.172133
0.327139
0.811036

In Christ,
Steven Watanabe


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk