C# 클래스 RandomOps.ThreadSafe.Wrapper

Wrapper for an RNG that makes the calls to Uniform(), Bool(), Byte(), and Bytes() thread-safe by locking the object. Note that it is the ThreadSafe object that is being locked and not the RNG object it wraps around, so calls to methods should always be made to the ThreadSafe-object and not to the RNG object directly. This works well for infrequent access to the RNG but for frequent access you should use e.g. ThreadSafe.MWC256 instead for performance reasons.
Derived calls are also thread-safe because they in turn call Uniform() and the other base-methods. If you use a custom RNG that have additional methods available which do not indirectly call one of the base-methods, then you must implement similar thread-safe wrappers. The RNG-object can potentially be locked several times by one thread because of how e.g. Bool() may call Uniform(), and such nested locking is supported in C#. It may be possible to implement more efficient locks for certain RNG's, e.g. for Ran2 we could instead implement a threadsafe version of the internal Rand() method.
상속: System.Random
파일 보기 프로젝트 열기: DanWBR/dwsim3

공개 메소드들

메소드 설명
Bool ( ) : bool

Thread-safe wrapper for Bool().

Byte ( ) : byte

Thread-safe wrapper for Byte().

Bytes ( int length ) : byte[]

Thread-safe wrapper for Bytes().

Enter ( ) : void

Same as a call to Monitor.Enter() on the RNG-object (not the ThreadSafe-object). Useful if you need to generate several random numbers in a batch without having to reacquire the lock for each call to the RNG.

Exit ( ) : void

Same as a call to Monitor.Exit() on the RNG-object (not the ThreadSafe-object). Must be called once for each call to Enter() to release the lock again.

Gauss ( ) : double

Thread-safe wrapper for Gauss().

The default implementation calls Uniform() a number of times. This wrapper therefore locks the RNG-object for the entirety of these multiple calls, instead of locking for each separate call to Uniform().

Uniform ( ) : double

Thread-safe wrapper for Uniform(). Note that derived methods that rely on Uniform() to create their random numbers, e.g. Gauss(), will automatically also be thread-safe.

Wrapper ( Random rand ) : System

Construct the thread-safe RNG wrapper.

메소드 상세

Bool() 공개 최종 메소드

Thread-safe wrapper for Bool().
public final Bool ( ) : bool
리턴 bool

Byte() 공개 최종 메소드

Thread-safe wrapper for Byte().
public final Byte ( ) : byte
리턴 byte

Bytes() 공개 최종 메소드

Thread-safe wrapper for Bytes().
public final Bytes ( int length ) : byte[]
length int Number of random bytes to return.
리턴 byte[]

Enter() 공개 메소드

Same as a call to Monitor.Enter() on the RNG-object (not the ThreadSafe-object). Useful if you need to generate several random numbers in a batch without having to reacquire the lock for each call to the RNG.
public Enter ( ) : void
리턴 void

Exit() 공개 메소드

Same as a call to Monitor.Exit() on the RNG-object (not the ThreadSafe-object). Must be called once for each call to Enter() to release the lock again.
public Exit ( ) : void
리턴 void

Gauss() 공개 최종 메소드

Thread-safe wrapper for Gauss().
The default implementation calls Uniform() a number of times. This wrapper therefore locks the RNG-object for the entirety of these multiple calls, instead of locking for each separate call to Uniform().
public final Gauss ( ) : double
리턴 double

Uniform() 공개 최종 메소드

Thread-safe wrapper for Uniform(). Note that derived methods that rely on Uniform() to create their random numbers, e.g. Gauss(), will automatically also be thread-safe.
public final Uniform ( ) : double
리턴 double

Wrapper() 공개 메소드

Construct the thread-safe RNG wrapper.
public Wrapper ( Random rand ) : System
rand System.Random The RNG to be made thread-safe.
리턴 System