I’m spending some time with Go on my free time. While its abilities fascinate me and expand my vision, I feel some back-steps time to time in the standard library.
Here is how to generate a random number in Go properly:
r := rand.New(rand.NewSource(time.Now().UnixNano()))
It’s the same way we did it in C. It’s not readable for a foreign eye, I expected a more proper, concise, and simple way to do this. In my opinion, it’s intuitive to expect a simple rand.Random() to generate a totally random value. I figured that there is enough documentation to indicate a time-related seed is necessary for random generation, but we could simplify things to not go over and over and over it again, like not inventing the wheel all over again each time we need a random integer value.
As always emphasized, there are no silver bullets in software practises.