}
// If the select in the goroutine is fair,
// cnt1 and cnt2 should be about the same value.
- // With 10,000 trials, the expected margin of error at
- // a confidence level of six nines is 4.891676 / (2 * Sqrt(10000)).
- r := float64(cnt1) / trials
- e := math.Abs(r - 0.5)
- t.Log(cnt1, cnt2, r, e)
- if e > 4.891676/(2*math.Sqrt(trials)) {
+ // See if we're more than 10 sigma away from the expected value.
+ // 10 sigma is a lot, but we're ok with some systematic bias as
+ // long as it isn't too severe.
+ const mean = trials * 0.5
+ const variance = trials * 0.5 * (1 - 0.5)
+ stddev := math.Sqrt(variance)
+ if math.Abs(float64(cnt1-mean)) > 10*stddev {
t.Errorf("unfair select: in %d trials, results were %d, %d", trials, cnt1, cnt2)
}
close(done)