Commit 3a825bc

bryfry <bryon@fryer.io>
2017-03-13 22:01:10
add rolls
1 parent 2f95ea5
chart.png → dice.png
File renamed without changes
main.go
@@ -16,12 +16,28 @@ type Trial struct {
 }
 
 func main() {
-	var num_trials = 500
 	var i uint64
 
+	fmt.Printf("n trials, max rand, variance, min, q1, q2, q3, max\n")
+	for i = 1; i < 100; i++ {
+		var max_rand = big.NewInt(120)
+		var num_trials = 2 << i
+		var exp_pis []float64
+		for i := 1; i <= 4096; i++ {
+			exp_pis = append(exp_pis, Experiment(max_rand, num_trials))
+		}
+		max, _ := stats.Max(exp_pis)
+		min, _ := stats.Min(exp_pis)
+		mean, _ := stats.Mean(exp_pis)
+		variance, _ := stats.Variance(exp_pis)
+		q, _ := stats.Quartile(exp_pis)
+		fmt.Printf("%d, %d, %f, %f, %f, %f, %f, %f\n", num_trials, max_rand, variance, min, q.Q1, mean, q.Q3, max)
+	}
+
 	fmt.Printf("n trials, max rand, variance, min, q1, q2, q3, max\n")
 	for i = 1; i < 100; i++ {
 		var max_rand = big.NewInt(2 << i)
+		var num_trials = 500
 		var exp_pis []float64
 		for i := 1; i <= 4096; i++ {
 			exp_pis = append(exp_pis, Experiment(max_rand, num_trials))
README.md
@@ -6,9 +6,13 @@ My question: If you could increase the sides of the dice (keeping # of dice roll
 
 Answer: Not really, 120 sided dice was probably good enough, you just need more rolls of the dice.
 
-![Pi via 500 dice throws](chart.png)
+![Pi via 500 n-sided dice throws](dice.png)
+![Pi via n 120-sided dice throws](rolls.png)
 
 Google spreadsheet with data and nice chart: https://goo.gl/Mkoqf6
+Sample size was 4096 for both tests 
+* 4k samples of n-sided dice with 500 rolls
+* 4k samples of n-rolls with 120-sided dice
 
 To run: 
 * install golang
rolls.csv
@@ -0,0 +1,16 @@
+n trials, max rand, variance, min, q1, q2, q3, max
+4, 120, NaN, 2.449490, 2.828427, +Inf, 3.464102, +Inf
+8, 120, NaN, 2.449490, 2.828427, +Inf, 3.464102, +Inf
+16, 120, 0.136218, 2.449490, 2.954196, 3.210289, 3.464102, 6.928203
+32, 120, 0.056686, 2.618615, 3.023716, 3.174226, 3.265986, 4.381780
+64, 120, 0.026399, 2.666667, 3.060368, 3.163387, 3.265986, 3.919184
+128, 120, 0.012637, 2.828427, 3.079201, 3.159189, 3.221549, 3.577709
+256, 120, 0.006391, 2.905092, 3.098387, 3.153581, 3.210720, 3.477713
+512, 120, 0.003316, 2.954196, 3.113013, 3.151620, 3.189386, 3.373096
+1024, 120, 0.001626, 3.012529, 3.122880, 3.151326, 3.178878, 3.294711
+2048, 120, 0.000817, 3.049925, 3.130342, 3.150269, 3.169767, 3.257514
+4096, 120, 0.000401, 3.075052, 3.135974, 3.149727, 3.163308, 3.222230
+8192, 120, 0.000200, 3.099598, 3.140218, 3.150124, 3.159451, 3.199000
+16384, 120, 0.000099, 3.115010, 3.143373, 3.150265, 3.156887, 3.183462
+32768, 120, 0.000050, 3.125362, 3.145270, 3.150076, 3.154969, 3.177163
+65536, 120, 0.000025, 3.133154, 3.146656, 3.150038, 3.153333, 3.170294
rolls.png
Binary file