make seed.txtar less likely to flake

Our test was essentially a "birthday paradox" simulation,
with 8 people in total and 7 possible birthdays.
Instead of checking whether two or more people share a birthday,
we tested whether six or more people shared a birthday.

Per a math/rand simulation with ten million iterations,
that test has a 0.13% flake rate.
That is low enough that we didn't immediately notice,
but high enough to realistically cause problems at some point.

My previous math in the test comment was clearly wrong.
First, we recently lowered the range by 1,
and `(1 / 7) ** 6` is three times higher as a probability.
Second, that's the probability of 6 people to share the same birthday,
without taking into account the extra two people in the total of 8.
That clearly drives the chances up, per the birthday paradox.

Double the number of people to 16,
and look for 14 or more to share a birthday.
The simulation returns a 0% chance at that point,
so it's extremely unlikely to cause issues.

Fixes #634.
pull/639/head
Daniel Martí 1 year ago
parent 45394ac13f
commit 5ede145791

@ -125,10 +125,10 @@ func mainFunc() {
println(imported.ImportedVar)
// When we're obfuscating, check that the obfuscated name lengths vary.
// With eight hashed names, and a range between 8 and 15,
// the chances of six repeats are (1 / 8) ** 6, or about 0.00038%.
// With sixteen hashed names, and a range of 7 (between 6 and 12),
// the chances of fourteen repeats are incredibly minuscule.
// If that happens, then our randomness is clearly broken.
if hashedNames[0] != "main.hashed0" {
if hashedNames[0] != "main.hashed_00" {
var count [16]int
for _, name := range hashedNames {
name = name[len("main."):]
@ -139,7 +139,7 @@ func mainFunc() {
panic("ended up with a hashed name that's too long: "+name)
}
count[len(name)]++
if count[len(name)] >= 6 {
if count[len(name)] >= 14 {
for _, name := range hashedNames {
println(name)
}
@ -163,18 +163,28 @@ func NamedFunc() string {
}
var hashedNames = []string{
hashed0(), hashed1(), hashed2(), hashed3(),
hashed4(), hashed5(), hashed6(), hashed7(),
hashed_00(), hashed_01(), hashed_02(), hashed_03(),
hashed_04(), hashed_05(), hashed_06(), hashed_07(),
hashed_08(), hashed_09(), hashed_10(), hashed_11(),
hashed_12(), hashed_13(), hashed_14(), hashed_15(),
}
func hashed0() string { return imported.CallerFuncName() }
func hashed1() string { return imported.CallerFuncName() }
func hashed2() string { return imported.CallerFuncName() }
func hashed3() string { return imported.CallerFuncName() }
func hashed4() string { return imported.CallerFuncName() }
func hashed5() string { return imported.CallerFuncName() }
func hashed6() string { return imported.CallerFuncName() }
func hashed7() string { return imported.CallerFuncName() }
func hashed_00() string { return imported.CallerFuncName() }
func hashed_01() string { return imported.CallerFuncName() }
func hashed_02() string { return imported.CallerFuncName() }
func hashed_03() string { return imported.CallerFuncName() }
func hashed_04() string { return imported.CallerFuncName() }
func hashed_05() string { return imported.CallerFuncName() }
func hashed_06() string { return imported.CallerFuncName() }
func hashed_07() string { return imported.CallerFuncName() }
func hashed_08() string { return imported.CallerFuncName() }
func hashed_09() string { return imported.CallerFuncName() }
func hashed_10() string { return imported.CallerFuncName() }
func hashed_11() string { return imported.CallerFuncName() }
func hashed_12() string { return imported.CallerFuncName() }
func hashed_13() string { return imported.CallerFuncName() }
func hashed_14() string { return imported.CallerFuncName() }
func hashed_15() string { return imported.CallerFuncName() }
-- imported/imported.go --
package imported

Loading…
Cancel
Save