Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
Verify distribution uniformity/Naive (view source)
Revision as of 20:13, 26 January 2010
, 14 years ago→{{header|Common Lisp}}
m (→{{header|JavaScript}}: not recommended to use for..in on arrays.) |
|||
Line 166:
NIL
#<EQL Hash Table{7} 200CB5BB></pre>
=={{header|D}}==
<lang d>import std.math: abs;
import std.string: format;
import std.stdio: writefln;
/**
Bin the answers to fn() and check bin counts are within +/- delta %
of repeats/bincount.
*/
void distCheck(TF)(TF func, int nrepeats, double delta) {
int[int] freqs;
for (int i; i < nrepeats; i++)
freqs[func()]++;
double target = nrepeats / cast(double)freqs.length;
int deltaCount = cast(int)(delta / 100.0 * target);
foreach (k, count; freqs)
if (abs(target - count) >= deltaCount)
throw new Exception(format("distribution potentially skewed for '%s': '%d'\n",
k, count));
writefln(freqs);
}</lang>
=={{header|Haskell}}==
|