Random numbers question

Hi, 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? Thanks a lot, Anant

AMDG Anant Rao wrote:
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

Steven, You're right... using the sample you sent, I get the same results on both Windows and Linux. The numbers from my app on Windows match with your sample output. So, something is amiss on Linux, though it's exactly the same code on both Linux and Windows. I'm scratching my head ... -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Friday, July 24, 2009 4:40 PM To: boost@lists.boost.org Subject: Re: [boost] Random numbers question AMDG Anant Rao wrote:
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 _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Thanks Steven! I found the issue - I was using boost 1.38 (which I incorrectly stated in my prev email that it was 1.39). I changed it to 1.39 and all's fine. Thanks again. -----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Steven Watanabe Sent: Friday, July 24, 2009 4:40 PM To: boost@lists.boost.org Subject: Re: [boost] Random numbers question AMDG Anant Rao wrote:
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 _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Anant Rao
-
Steven Watanabe