February 13, 2008 [Issue 1831] New: Random seeding appears not to work | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=1831 Summary: Random seeding appears not to work Product: D Version: 2.010 Platform: PC URL: http://www.digitalmars.com/d/2.0/phobos/std_random.html OS/Version: Windows Status: NEW Severity: major Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: ig405@zepler.net unpredictableSeed always returns the same value, across multiple runs and when run in a loop. seeding with rand() instead should in theory work, but my Random is always returning the same sequence across multiple program runs. I have tried all the methods in the documentation (see url) to no avail so I'd like to know if anyone else has issues with this. import std.random; class Die{ Random rnd; int value; int maxValue ... this() { ... Random rnd = Random(<seed>); roll(); } int roll() { value = rnd.next() % maxValue; return value; } } -- |
February 13, 2008 [Issue 1831] Random seeding appears not to work | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=1831 andrei@metalanguage.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALID ------- Comment #1 from andrei@metalanguage.com 2008-02-13 12:43 ------- unpredictableSeed works properly (except that it will be changed to return uint instead of ulong in the next releast). You should just change your constructor to: this() { ... rnd = Random(<seed>); roll(); } so it doesn't define an automatic variable of the same name as the member. -- |
Copyright © 1999-2021 by the D Language Foundation