2 ms·
Put this in a test.go file locally and run it repeatedly with "go run test.go": package main func main() { x := map[string]string{"A": "", "B"
by jerf 13y ago
Put this in a test.go file locally and run it repeatedly with "go run test.go":
package main
func main() {
x := map[string]string{"A": "", "B": "", "C": "", "D": "", "E": ""}
for key, _ := range(x) {
print(key + "\n")
}
print("\nNext iter:\n")
for key, _ := range(x) {
print(key + "\n")
}
}
You'll see the order can change even within a single run. It does not appear to be uniformly random; I had to put 5 keys in because it happened far less often than expected with 3 keys, but you can see randomization often enough with this.
Normally, I'd link to the Go Playground, but this doesn't manifest there "correctly", probably due to caching of the results.