Class TSRandom
A Thread Safe random class
Inherited Members
Namespace: SuperOfficeUtil
Assembly: SoCore.dll
Syntax
public class TSRandom
Remarks
https://andrewlock.net/building-a-thread-safe-random-implementation-for-dotnet-framework/
Dont initialize a new random for each invocation
- makes for the same seed if called multiple times in a short time-span
- resulting in same "random" output.
Random() is also not thread safe, keeping a static Random() per thread solves the problem of calling Random.Next() from several threads within 15 ms can give the same values multiple times.
Constructors
TSRandom()
Declaration
public TSRandom()
Methods
Init()
Declaration
public void Init()
Next()
Declaration
public int Next()
Returns
| Type | Description |
|---|---|
| int |
Next(int)
Declaration
public int Next(int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | max |
Returns
| Type | Description |
|---|---|
| int |
Next(int, int)
Declaration
public int Next(int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| int | min | |
| int | max |
Returns
| Type | Description |
|---|---|
| int |
NextDouble()
Declaration
public double NextDouble()
Returns
| Type | Description |
|---|---|
| double |