ThreadSafeRandomCreate(FuncRandom) Method

Creates a ThreadSafeRandom instance using the specified factory in each thread the result is accessed from.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 10.0.0
C#
public static ThreadSafeRandom Create(
	Func<Random>? factory
)

Parameters

factory  FuncRandom
A delegate that will be invoked once in each thread the created instance is used from.

Return Value

ThreadSafeRandom
A ThreadSafeRandom instance using the specified factory in each thread the result is accessed from.

Remarks

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.

  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.

See Also