Pages

2024-05-06

Yet another reason to love Go: math/rand/v2

With the recent explanation of how math/rand evolved into math/rand/v2 I got reminded why I first fell in love with Go. Design decisions are not always made to match what every body else is doing, but rather what is the better decision. By some definition of better that I happen to agree with.

While the blog post on math/rand/v2 goes into interesting details around different pseudo random algorithms, exciting optimizations, and how to generally update a widely used library (like the standard library) with new versions are all interesting it is really three other things that make me even more excited.

One of the first things that I appreciate is the openness in recognizing that the original math/rand library has several bad design decisions in it. And this is a tone in the whole article. Very appreciated and directly related to the next two things I'm excited about.

It might seem like a small thing but the fact that the new library recognizes that different pseudo random algorithms needs to be seeded in different ways, just like different crypto algorithms need to be seeded (with a key and other parameters) in different ways.

But the final thing is really the best; the removal of the Read method from any math/rand/v2 types since this introduces a risk of accidently using the weaker randomness in math/rand vs the cryptographically secure crypto/rand package. In my opinion this shows and amazing attention to detail and is definitely in the spirit of Go - prevent developers from accidently making mistakes.

No comments:

Post a Comment