[OT] Generating distribution of N dice rolls

Siarhei Siamashka siarhei.siamashka at gmail.com
Fri Nov 11 00:33:33 UTC 2022


On Thursday, 10 November 2022 at 22:18:47 UTC, Ali Çehreli wrote:
> I was half joking anyway but the values 4_000 and 'average / 
> 20', respectively produce closer values:
>
> [16663617, 16663620, 16662052, 16671587, 16663818, 16675306]

Yes, this particular result looks okish (when tested by the 
XNomial R package):

     P value (LLR) = 0.11807 ± 0.00102

You can modify your code this way:

```D
void main() {
     auto results = diceDistrib!6(100_000_000);
     auto expected_probabilities = [1.0 / 6].replicate(6);
     writefln("# Paste this to https://rdrr.io/cran/XNomial/");
     writefln("library(XNomial)");
     writefln("experimental_results <- c(%(%s, %))", results);
     writefln("expected_probabilities <- c(%(%.18f, %))", 
expected_probabilities);
     writefln("xmonte(experimental_results, 
expected_probabilities)");
}
```

And then paste its output to https://rdrr.io/cran/XNomial/ to 
calculate p-value. If the reported p-value is smaller than 0.05, 
then we can be 95% confident that the generator is working 
incorrectly. A p-value higher than 0.05 means that the test can't 
see anything wrong, but this doesn't guarantee anything and isn't 
a proof of correctness.

Even a correct generator can sporadically have p-values smaller 
than 0.05, but this happens only in roughly 1 out of 20 runs (in 
other words, there's a 5% false positive chance). This situation 
is explained by https://xkcd.com/882/


More information about the Digitalmars-d mailing list