Fix occasional crash due to calling rand.Intn(0)