I used the rand.Intn(n int) function to swap elements inside a slice, but everytime I ran the program, the output was the same random sequence of elements inside slice.
What obvious thing am I missing here ?
I used the rand.Intn(n int) function to swap elements inside a slice, but everytime I ran the program, the output was the same random sequence of elements inside slice.
What obvious thing am I missing here ?
From documentation
Use the Seed function to initialize the default Source if different behavior is required for each run.
If Seed is not called, the generator behaves as if seeded by Seed(1).
By default you get same seed every run.
You can use current time as seed to get less deterministic sequences.
rand.Seed(time.Now().UTC().UnixNano())