View mode: basic / threaded / horizontal-split · Log in · Help
May 13, 2009
[Issue 2977] New: std.random.unpredictableSeed() should use thread ID somewhere
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@digitalmars.com
       ReportedBy: dsimcha@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: -------
October 11, 2009
[Issue 2977] std.random.unpredictableSeed() should use thread ID somewhere
http://d.puremagic.com/issues/show_bug.cgi?id=2977


Andrei Alexandrescu <andrei@metalanguage.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|NEW                         |ASSIGNED
                CC|                            |andrei@metalanguage.com
        AssignedTo|nobody@puremagic.com        |andrei@metalanguage.com


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 01, 2009
[Issue 2977] std.random.unpredictableSeed() should use thread ID somewhere
http://d.puremagic.com/issues/show_bug.cgi?id=2977


David Simcha <dsimcha@yahoo.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|ASSIGNED                    |RESOLVED
        Resolution|                            |FIXED


--- Comment #1 from David Simcha <dsimcha@yahoo.com> 2009-12-01 06:21:29 PST ---
Fixed SVN.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 06, 2009
[Issue 2977] std.random.unpredictableSeed() should use thread ID somewhere
http://d.puremagic.com/issues/show_bug.cgi?id=2977


Walter Bright <bugzilla@digitalmars.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |bugzilla@digitalmars.com


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2009-12-06 00:50:37 PST ---
Fixed dmd 2.037

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Top | Discussion index | About this forum | D home