Anonymous user
Unbias a random generator: Difference between revisions
Updated D entry
(→{{header|Ruby}}: Too much ones, not enough zeros...changed rand_n) |
(Updated D entry) |
||
Line 372:
=={{header|D}}==
<lang d>import std.stdio, std.random, std.algorithm, std.range, std.functional;
bool biased(in int n) /*nothrow*/ {
Line 385 ⟶ 387:
void main() {
▲ alias reduce!q{a + b} sum; /**/
enum int M = 500_000;
foreach (immutable n; 3 .. 7)
a2 = sum(0, iota(M).map!(_=> unbiased(n))());▼
writefln("%d: %2.3f%% %2.3f%%", n,
}</lang>
{{out}}
|