Faster weighted choice range

bearophile bearophileHUGS at lycos.com
Wed Dec 28 18:48:49 PST 2011


Along the time time I have put in Bugzilla a good amount of code for Phobos.

In Bugzilla I have an enhancement request that asks to turn std.random.dice into a range:
http://d.puremagic.com/issues/show_bug.cgi?id=5849

Through Reddit I have found an efficient O(1) weighted choice:
http://www.keithschwarz.com/darts-dice-coins/

So I have translated the Java code, with small changes, into a D almost-range:
http://codepad.org/Ipp6R3DR
The code contains some questions, some TODOs, and probably a Range mistake too.

Bye,
bearophile


More information about the Digitalmars-d mailing list