[Issue 2977] New: std.random.unpredictableSeed() should use thread ID somewhere
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed May 13 13:26:07 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2977
Summary: std.random.unpredictableSeed() should use thread ID
somewhere
Product: D
Version: 2.030
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: bugzilla at digitalmars.com
ReportedBy: dsimcha at yahoo.com
uint unpredictableSeed()
{
static bool seeded;
static MinstdRand0 rand;
if (!seeded) {
rand.seed(getpid ^ cast(uint)getUTCtime);
seeded = true;
}
rand.popFront;
return cast(uint) (getUTCtime ^ rand.front);
}
If called from multiple threads at exactly the same time, unpredictableSeed
gives every thread the same seed. This is annoying when running the same monte
carlo simulation simultaneously in multiple threads, since I tend to spawn all
of the threads at exactly the same time. Something like:
(getpid + cast(uint) Thread.getThis) ^ cast(uint) getUTCtime
might work well.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list