Experimental approach to reference-type random number generators

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sun Sep 1 06:26:13 PDT 2013


On 01/09/13 14:21, bearophile wrote:
> See also this idea (and API problem):
> http://d.puremagic.com/issues/show_bug.cgi?id=5849

On dice(): I think this is one case of what is in practice a random number 
_distribution_, akin to uniform().

My own instinct is that as much as possible, random number distributions should 
come in two forms -- functions, and ranges.  So, it should be possible to go,

     foreach(_; 0 .. 10)
     {
         writeln(uniform(0.0, 1.0));
         writeln(dice(10, 5, 7));
     }

but equally well to go,

     auto uniDist = uniformDistribution(0.0, 1.0);
     auto biasedDice = diceDistribution(10, 5, 7);
     foreach(u, d; lockstep(uniDist, biasedDice).take(10))
     {
         writeln(u);
         writeln(d);
     }

(I'm sure you can find something to improve in how I've written the second 
example, but you get the idea of how the distributions could behave:-)


More information about the Digitalmars-d mailing list