March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -1,13 +1,13 @@
|
|||
import std.stdio, std.random, std.string, std.range;
|
||||
|
||||
void main() {
|
||||
import std.stdio, std.random, std.string, std.range;
|
||||
|
||||
enum int nTrials = 1_000_000;
|
||||
enum items = "aleph beth gimel daleth he waw zayin heth".split();
|
||||
enum pr = [1/5., 1/6., 1/7., 1/8., 1/9., 1/10., 1/11., 1759/27720.];
|
||||
const items = "aleph beth gimel daleth he waw zayin heth".split;
|
||||
const pr = [1/5., 1/6., 1/7., 1/8., 1/9., 1/10., 1/11., 1759/27720.];
|
||||
|
||||
double[pr.length] counts = 0.0;
|
||||
foreach (_; 0 .. nTrials)
|
||||
counts[dice(pr)]++;
|
||||
foreach (immutable _; 0 .. nTrials)
|
||||
counts[pr.dice]++;
|
||||
|
||||
writeln("Item Target prob Attained prob");
|
||||
foreach (name, p, co; zip(items, pr, counts[]))
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
import std.stdio, std.random, std.algorithm, std.range;
|
||||
|
||||
void main() {
|
||||
import std.stdio, std.random, std.algorithm, std.range;
|
||||
|
||||
enum int nTrials = 1_000_000;
|
||||
auto items = "aleph beth gimel daleth he waw zayin heth".split();
|
||||
enum pr = [1/5., 1/6., 1/7., 1/8., 1/9., 1/10., 1/11., 1759/27720.];
|
||||
const items = "aleph beth gimel daleth he waw zayin heth".split;
|
||||
const pr = [1/5., 1/6., 1/7., 1/8., 1/9., 1/10., 1/11., 1759/27720.];
|
||||
|
||||
double[pr.length] cumulatives = pr[];
|
||||
foreach (i, ref c; cumulatives[1 .. $ - 1])
|
||||
foreach (immutable i, ref c; cumulatives[1 .. $ - 1])
|
||||
c += cumulatives[i];
|
||||
cumulatives[$ - 1] = 1.0;
|
||||
|
||||
double[pr.length] counts = 0.0;
|
||||
auto rnd = Xorshift(unpredictableSeed());
|
||||
foreach (_; 0 .. nTrials) {
|
||||
double rnd01 = rnd.front / cast(double)rnd.max;
|
||||
rnd.popFront();
|
||||
counts[cumulatives[].countUntil!(c => c >= rnd01)()]++;
|
||||
auto rnd = Xorshift(unpredictableSeed);
|
||||
foreach (immutable _; 0 .. nTrials) {
|
||||
immutable rnd01 = rnd.front / double(rnd.max);
|
||||
rnd.popFront;
|
||||
counts[cumulatives[].countUntil!(c => c >= rnd01)]++;
|
||||
}
|
||||
|
||||
writeln("Item Target prob Attained prob");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue