IMHO, the best idea is to keep the generator in a strict state record . Then you can use regular do-Syntax to work with the generator. Sowing is performed only once - at the beginning of the main program (or at the beginning of each thread). You can avoid I / O by using an operation splitthat gives two random generators from one. (Different, of course).
Since the condition is still clean, thread safety can be guaranteed. In addition, you can always escape the state by providing a random function generator. This is useful, for example, in the case of automatic unit tests.
source
share