Note
If factory creates a pseudo random number generator, then in order not to produce the same sequence from the different threads make sure the factory method creates instances with different seeds.
public static ThreadSafeRandom Create(
Func<Random>? factory
)
Public Shared Function Create (
factory As Func(Of Random)
) As ThreadSafeRandom
public:
static ThreadSafeRandom^ Create(
Func<Random^>^ factory
)
static member Create :
factory : Func<Random> -> ThreadSafeRandom
Make sure the created instance is disposed if it is not used anymore even if the created instances are not disposable.
Disposing the created instance disposes also the Random instances created by the factory if the created Random instances are disposable.