-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Hereby, I would like to petition to reopen and salvage #18514.
There are several areas where having a global, performant and lock free random source is of very high utility.
-
Development/testing of concurrent apps/algorithms (and Go is all about concurrency). One of the most potent techniques in this area requires placing random delays all over the code to emulate uneven progress of concurrent goroutines. Present implementation of
rand.Int()with a global lock in its path all but negates the usefulness of this approach. -
Zero communication "unfair" sharing. Go is commonly used to implement various proxies, load balancers and other similar gadgets, which require "unfair" sharing of resources across multiple instances (example applications include AB testing, canary deployments, various types of hot failovers and so on). This can be efficiently achieved by means of random selection with custom probability distribution and very efficient algorithms were developed for this purpose (such as Walker-Vose O(1) uneven sampling algorithm). Unfortunately, "unfair" selection can only be as performant as the underlying uniform random source is.
-
"Locally distributed" data structures. A good, simple example of those is Java's
java.util.concurrent.atomic.LongAccumulatorand friends (however, same technique can be applied to other similarly constructed objects, such as concurrent pools, multiple producer queues, and so on).sync.Poolcunningly uses the privatefastrand(), we, the users, want one too! :-)
In most other languages these problems are resolved by means of thread local PRNGs. In my opinion, Go should also expose one, or, rather, make its global PRNG instance behave like one. It does not even requires any changes to the language, because at present users have no ability to affect the private rand.globalRand object in any way and thus can have no preference on what sort of pseudo-random sequence is returned from gloabal rand functions.