having a problem seeding random number generator.
I'm just starting out with boost, and I'm playing around with the random
library. I'm writing a class that is supposed to simulate a six-sided die.
It compiles and everything works, except seeding the mt19937. Every time I
try testing this class, I get the same numbers, no matter what value I call
my seed method with. If I use the constructor that takes a seed value, I
get different numbers, but reseeding the object still doesn't seem to have
any effect. Any ideas?
#include
Some more information: I'm using gcc 4.0.2 on Ubuntu, with the latest available version of Boost (for Ubuntu anyway. It's 1.32.0+1.33.0-cvs20050727). Using different generators, such as rand48, mt11213b, or minstd_rand, has no effect; I get different numbers, but reseeding still doesn't change them. Here is the test code I'm using: #include "d6.h" #include <iostream> #include <fstream> int main() { D6 die; std::ifstream in("/dev/random"); if(!in) { return -1; } unsigned long s; in >> s; std::cout << "Seed: " << s << std::endl; die.seed(s); for (int i = 0; i < 20; i++) std::cout << die.roll() << std::endl; } Any ideas or suggestions would be appreciated. I'm pretty much baffled. -- Jim
Jim Ingram wrote:
Some more information:
I'm using gcc 4.0.2 on Ubuntu, with the latest available version of Boost (for Ubuntu anyway. It's 1.32.0+1.33.0-cvs20050727). That's the version from Ubuntu Breezy, 1.33.1 is in Dapper.
I'm writing a class that is supposed to simulate a six-sided die. It compiles and everything works, except seeding the mt19937. Every time I try testing this class, I get the same numbers, no matter what value I call my seed method with. The problem is that 'variate_generator' stores a copy of the engine, not a reference. So this works:
#include
Daniel James
The problem is that 'variate_generator' stores a copy of the engine, not a reference.
Wow. You'd think that between the docs, the header files, and the example code, I would have caught that. It does make a lot more sense to have the generator and distribution encapsulated inside a variate_generator instead of maintaining them seperately. Thanks for pointing that out. -- Jim
Jim Ingram wrote:
I'm just starting out with boost, and I'm playing around with the random library. I'm writing a class that is supposed to simulate a six-sided die. [--snip--]
I would stay away from the Boost.Random library. Judging by recent
postings on the list there are serious bugs in it and it is essentially
unmaintained.
--
Bardur Arantsson
Bárður Árantsson
I would stay away from the Boost.Random library. Judging by recent postings on the list there are serious bugs in it and it is essentially unmaintained.
I've pretty much come to the same conclusion. I might just write my own Mersenne Twister class and be done with it, since I don't really need all the other generators and distributions. I like the idea behind Boost.Random, but it seems to be more trouble than it's worth. Thanks for the reply, -- Jim
participants (3)
-
Bárður Árantsson
-
Daniel James
-
Jim Ingram