Boost logo

Boost :

Subject: Re: [boost] [random] seeding with arbitrary integers
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-21 13:39:15

Robert Ramey wrote:
> Steven Watanabe wrote:
> > Currently, the statement
> > boost::minstd_rand gen(time(0));
> > will work almost all the time.
> >
> > However, it is wrong because it will fail
> > when time(0) returns 2147483647.
> again, can't this be trapped?

During testing, that code might work without trouble. Then, when put into production, it fails, but only on some systems (or for some customers). That's hardly helpful, but suppose you try to debug the problem. Will it ever fail on you? Only on Jan 18 2038 at 22:14:07 EST (when time() returns 2147483647). If it failed in production, and you're now debugging it, the time must be after the bad value, so will it fail for you?

The point is that unless minstd_rand_gen() throws an exception that indicates the failed value, you'd be hard pressed to understand why the failure occurred. Yes, you could study the valid input range, compare that to the valid output range of time(), and determine that they don't match, but that's a pain. Even if you know about the bad input, do you really want code that worked so well for so long to suddenly start failing? Maybe.

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

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