digitalmars.D.bugs - [Issue 2352] New: unittest fails randomly
- d-bugmail puremagic.com (16/16) Sep 10 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2352
- Jarrett Billingsley (3/19) Sep 10 2008 Looks like the unpredictable seed... isn't so unpredictable!
- d-bugmail puremagic.com (32/32) Sep 10 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2352
- d-bugmail puremagic.com (16/46) Sep 10 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2352
http://d.puremagic.com/issues/show_bug.cgi?id=2352
Summary: unittest fails randomly
Product: D
Version: 2.019
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: bugzilla digitalmars.com
ReportedBy: bartosz relisoft.com
I run unittest a lot and from time to time I see this error:
Error: AssertError Failure std.random(476)
It's hard to reproduce.
--
Sep 10 2008
On Wed, Sep 10, 2008 at 7:17 PM, <d-bugmail puremagic.com> wrote:
http://d.puremagic.com/issues/show_bug.cgi?id=2352
Summary: unittest fails randomly
Product: D
Version: 2.019
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: bugzilla digitalmars.com
ReportedBy: bartosz relisoft.com
I run unittest a lot and from time to time I see this error:
Error: AssertError Failure std.random(476)
It's hard to reproduce.
--
Looks like the unpredictable seed... isn't so unpredictable!
Sorry.
Sep 10 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2352
andrei metalanguage.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
The unpredictable seed is meant to vary from one run to the next, not
necessarily from one call to the next, so the test is a bit incorrect. The
function does this:
uint unpredictableSeed()
{
static uint moseghint = 87324921;
return cast(uint) (getpid ^ getUTCtime ^ ++moseghint);
}
(Bonus q: what does moseghint mean?)
If it so happens that getUTCtime and moseghint e.g. change only LSB in lockstep
from one call to the next, the returned values will be identical. I changed the
function to this:
uint unpredictableSeed()
{
static bool seeded;
static MinstdRand0 rand;
if (!seeded) {
rand.seed(getpid ^ getUTCtime);
}
return cast(uint) (getUTCtime ^ rand.next);
}
It'll be a bit slower but also quite a bit less predictable. But I also removed
the assert because even with the implementation above, it's not guaranteed that
two successive returns can't be equal.
--
Sep 10 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2352
The unpredictable seed is meant to vary from one run to the next, not
necessarily from one call to the next, so the test is a bit incorrect. The
function does this:
uint unpredictableSeed()
{
static uint moseghint = 87324921;
return cast(uint) (getpid ^ getUTCtime ^ ++moseghint);
}
(Bonus q: what does moseghint mean?)
If it so happens that getUTCtime and moseghint e.g. change only LSB in lockstep
from one call to the next, the returned values will be identical. I changed the
function to this:
uint unpredictableSeed()
{
static bool seeded;
static MinstdRand0 rand;
if (!seeded) {
rand.seed(getpid ^ getUTCtime);
}
return cast(uint) (getUTCtime ^ rand.next);
}
It'll be a bit slower but also quite a bit less predictable. But I also removed
the assert because even with the implementation above, it's not guaranteed that
two successive returns can't be equal.
I meant:
uint unpredictableSeed()
{
static bool seeded;
static MinstdRand0 rand;
if (!seeded) {
rand.seed(getpid ^ getUTCtime);
seeded = true;
}
return cast(uint) (getUTCtime ^ rand.next);
}
It's in SVN.
--
Sep 10 2008









"Jarrett Billingsley" <jarrett.billingsley gmail.com> 