[Issue 5849] std.random.dice is better as a range

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 31 17:47:47 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=5849



--- Comment #8 from bearophile_hugs at eml.cc 2013-08-31 17:47:46 PDT ---
(In reply to comment #7)

> import std.stdio, std.random, std.range;
> void main() {
>     immutable probabilities = [0.2, 0.6, 0.1, 0.1];
>     immutable values = "ACGT";
>     probabilities.diceRange(values).take(10).writeln;
> }
> 
> 
> This is quite handy.

If the second optional argument is not supported, then the code becomes:


import std.stdio, std.random, std.range;
void main() {
    immutable probabilities = [0.2, 0.6, 0.1, 0.1];
    immutable values = "ACGT";
    probabilities.diceRange.map!(i => values[i]).take(10).writeln;
}


But I am not sure it's strictly equivalent.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list