Class TSRandom
A Thread Safe random class
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public class TSRandom : Object
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()
A Thread Safe random class
Declaration
public 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.
Methods
Init()
A Thread Safe random class
Declaration
public void Init()
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.
Next()
A Thread Safe random class
Declaration
public int Next()
Returns
Type | Description |
---|---|
Int32 |
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.
Next(Int32)
A Thread Safe random class
Declaration
public int Next(int max)
Parameters
Type | Name | Description |
---|---|---|
Int32 | max |
Returns
Type | Description |
---|---|
Int32 |
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.
Next(Int32, Int32)
A Thread Safe random class
Declaration
public int Next(int min, int max)
Parameters
Type | Name | Description |
---|---|---|
Int32 | min | |
Int32 | max |
Returns
Type | Description |
---|---|
Int32 |
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.
NextDouble()
A Thread Safe random class
Declaration
public double NextDouble()
Returns
Type | Description |
---|---|
Double |
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.