vendredi 23 février 2018

How to create a thread-safe rand.Source?

The documentation for the standard-library rand.NewSource function states that,

Unlike the default Source used by top-level functions, this source is not safe for concurrent use by multiple goroutines.

Is there a way to create a thread-safe rand.Source?

Context: I have a type with a method that may be called by multiple go-routines, and this method uses random numbers. I want to support dependency injection for testing, so I can't use the default Source.




Aucun commentaire:

Enregistrer un commentaire