On 02/09/13 00:54, bearophile wrote:
diceDistribution() is much more efficient than calling dice() many times in map.
Surely, but you should have both available in any case. I think there's a good
argument that for all random number distributions, there should be a function
_and_ a range implementation, so depending on your needs do either:
auto dist = someDistribution(/* ... parameters ... */, rng);
foreach (x; dist.take(10))
{
writeln(x);
}
... or:
foreach(_; 0 .. 10)
{
auto x = some(/* ... parameters ... */, rng);
writeln(x);
}
Of course in practice sometimes the range might just wrap the function, or the
function might contain within a static instance of the range.