I think there's another bug in the generateSlice function if the intention is to create a slice with n random numbers.
func generateSlice(n int) []int {
s := make([]int, n)
for i := 0; i < n; i++ {
s = append(s, rand.Intn(1e9))
}
return s
}
As it is now, the function creates a slice with n zeros followed by n random numbers. I suppose you meant to say make([]int, 0, n). You could just as well assign directly to each slice element instead of using append, which would be more efficient.
I made the exact same mistake quite a few times myself.
I made the exact same mistake quite a few times myself.