D-Programming-Language/phobos — pull request #1702 by Zshazz (2013-11-18 22:37:08+00:00)
Title: Fix issue 5849 - Add a dice range type to std.random

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

This pull provides a range interface to simulate dice rolls much like `dice`. The difference is that this `diceRange` can do some preprocessing to the proportions vector to make it much faster to do repeated rolls with the same die. The algorithm used is simply a cumulative sum array with binary search, so the implementation is straightforward.

A benefit from this type of implementation is that it is _essentially equivalent_ to the current dice implementation when `double`s are used. One of the test cases in the unittest covers that. This should allow a user to nearly drop-in replace dice calls and get precisely the same results if needed.

Some internals are exposed in the form of template parameters which can allow a user to optimize the dice rolls for their particular data.

See also (for a use case):
http://forum.dlang.org/thread/prkthuzsmbppjltvohdh@forum.dlang.org?page=5