Hacker News new | ask | show | jobs
by dmitrim 3021 days ago
Thanks for pointing it out. Should clearly not depend on the number of iterations. It's fixed now.
1 comments

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.

Yep, that meant to be capacity, not length. Corrected. Thanks!