Fast thread-safe randomness in Go

This post is about how to generate uniformly distributed numbers thread safely and as fast as possible. It does involve randomness but we do not aim at generating cryptographically secured random numbers. The use cases vary, but a common example is to pick an element from a slice uniformly for each HTTP request in an HTTP server. Given the way the net/http library is, one cannot fiddle with the entrypoint before the request handling is launched in its own goroutine....

July 10, 2021 · 10 min · Quentin McGaw