|
Boost Users : |
Subject: Re: [Boost-users] Random: How to get a different seed?
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2011-01-24 16:26:48
On Monday, 24. January 2011 22:11:55 Steven Watanabe wrote:
> AMDG
>
> On 1/24/2011 12:57 PM, Lasse Kliemann wrote:
> > I use /dev/urandom for this, like so (code fragments):
> > FILE *dev_urandom;
> > uint32_t seed;
> > if((dev_urandom = fopen("/dev/urandom", "r")) == NULL) throw /* error
> > */ if(fread(&seed, sizeof(seed), 1, dev_urandom) == 0) throw /* error
> > */ if(fclose(dev_urandom) != 0) throw /* error */
> > boost::mt19937 gen(seed);
> >
> > But maybe there are even better ways.
>
> boost::random_device seed_gen;
> boost::mt19937 gen(seed_gen());
>
> should have the same effect and is more portable.
>
Nice. Thank you.
> In Christ,
> Steven Watanabe
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
Best,
Cedric
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