Author

Topic: Tutorial: Using R to statistically test a die for bias (Read 650 times)

pf
full member
Activity: 176
Merit: 105
In the following, we assume a 6-sided die. If you have another type of die, adjust accordingly.

Now, roll your die a hundred times and record the results on a piece of paper or an offline computer. (Or an online computer if the results are not sensitive. But if you are using the die to generate a private key, the results are sensitive, so be careful.)

This is how you use the statistical software R to test your results for bias:

  • Run R by typing R on the Terminal.
  • Type rolls = c(1,2,3,4,5,6,1,2,3,4,5,6,...,1,2,3,4,5,6) to store your hundred numbers from 1 to 6. Of course, that the previous thing (containing "...") is not valid code. You should put all of your hundred numbers in there separated with commas.
  • Type frequency = table(rolls)
  • Type chisq.test(frequency)
  • Take a look at the resulting p-value. The p-value basically tells you: What is the probability that a truly random die will produce results even more extreme than the results we're seeing? (Source.) To keep it simple: If this is higher than 0.1, there is no evidence of bias. Otherwise, there is evidence of bias.

See also my other tutorials:
Tutorial: Installing R on an offline Ubuntu computer
Tutorial: Compiling Armory and getting it onto an offline computer
Tutorial: Creating a bulletproof 255-bit entropy Armory wallet
Jump to: