[Issue 5849] std.random.dice is better as a range

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 22 04:44:09 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=5849



--- Comment #10 from bearophile_hugs at eml.cc 2013-11-22 04:43:56 PST ---
See also:
http://www.keithschwarz.com/interesting/code/?dir=alias-method

Once paid the time to create the range, all the successive popFront() become
just something like this (where for speed nextDouble is not a call to
uniform(), but it's more like uniform01):

int column = random.nextInt(probability.length);
boolean coinToss = random.nextDouble() < probability[column];
return coinToss ? column : alias[column];

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list