[phobos] fastDice

David Simcha dsimcha at gmail.com
Sat Sep 11 13:29:17 PDT 2010


  I've written a few functions that generate random numbers from an 
arbitrary discrete distribution in O(log N) time, where N is the number 
of possible values, using SortedRange.lowerBound().  It's similar to 
dice() except that in exchange for O(N) auxiliary space and upfront 
initialization cost you get O(log N) generation.  I've attached the 
code, which is fairly simple.  Should this go in std.random, or is 
needing this O(log N) performance on dice() niche enough that this 
belongs in my dstats lib instead?
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fastDice.d
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100911/110a4d41/attachment.ksh>


More information about the phobos mailing list