Boost logo

Boost :

From: Christopher Kormanyos (e_float_at_[hidden])
Date: 2020-06-20 10:40:45

> So would following the crowd and using time(0)> be simplest?
I never liked time(0) for that particular use casebecause in the old days it had multiple millisecondresolution and lacked the seed resolution sometimes.
I do not know it the code below is best practice,but I usually use some kind of variation of below.You can switch system_clock for high_resolution_clock.
All this is straight off-the-rack C++11.

#include <chrono>
#include <iostream>
#include <random>

// Use time point now seed to get a different set of values each time.
const std::mt19937::result_type seed =

// uint32_t
static std::mt19937 gen(seed);

int main()
  std::cout << gen() << std::endl;

    On Thursday, June 18, 2020, 10:27:27 AM GMT+2, Paul A Bristow via Boost <boost_at_[hidden]> wrote:

> -----Original Message-----
> From: Boost <boost-bounces_at_[hidden]> On Behalf Of John Maddock via Boost
> Sent: 17 June 2020 18:48
> To: Paul A Bristow via Boost <boost_at_[hidden]>
> Cc: John Maddock <jz.maddock_at_[hidden]>
> Subject: Re: [boost] Boost.Random
> On 17/06/2020 15:53, Paul A Bristow via Boost wrote:
> > I have wanted to use boost::random::random_device; as a seeder for my generator.
> >
> > #include <boost/random/random_device.hpp> // For
> > boost::random::random_device; seeder
> >
> > But using this requires that I link to a library file // LINK : fatal
> > error LNK1104: cannot open file 'libboost_random-vc142-mt-gd-x64-1_73.lib'
> >
> > So I have instead used C++ std random device successfully
> >
> >    using std::random_device;
> >    random_device seeder;
> >    // Use seeder to get a different set of values each time.
> >    static boost::random::mt19937 gen(seeder()); // uint32_t
> >
> > But is there any way I can stick to the Boost version (I imagine that it might prove more
> > Or is this a delusion?)
> What do you mean by portable?  random_device is inherently non-portable because it's.... random ;)

By portable I mean 'works on as many platforms and C++ standard versions as possible'.
> In many ways this is something that the std:: version does best as the system implementer knows
> how to implement on their OS.  Or you could just link to Boost.Random of course which would work
> nearly everywhere too I'm sure.

I was just puzzled why Boost.Random needed to *link* when std:random_device doesn't  appear to.  Is
it quietly linking to a standard library?


PS Thanks for the even-more-random suggestions but I really, really don't care how randomly random
it is for my application.

So would following the crowd and using time(0) be simplest?

Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at