DEV Community

Discussion on: Math/Rand in GoLang

Collapse
mrsaeeddev profile image
Saeed Ahmad

I think there's some issue with seeding. By default, it seeds some constant. I tried it on 10, 100, 1000, and 1000. It gives the same number i.e 0, 1, 81, 81 and 8081 respectively no matter how many times you repeatedly run it. Docs of golang also suggest that to avoid this behavior you should seed the rand with some value which constantly changes like time.Now().UnixNano().