Bug 1831 – Random seeding appears not to work

Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2008-02-13T12:22:00Z
Last change time
2015-06-09T01:14:30Z
Assigned to
bugzilla
Creator
ig405

Comments

Comment #0 by ig405 — 2008-02-13T12:22:39Z
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; } }
Comment #1 by andrei — 2008-02-13T12:43:34Z
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.