Show / Hide Table of Contents

Class TSRandom

A Thread Safe random class

Inheritance
object
TSRandom
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Util
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()

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
int
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(int)

A Thread Safe random class

Declaration
public int Next(int max)
Parameters
Type Name Description
int max
Returns
Type Description
int
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(int, int)

A Thread Safe random class

Declaration
public int Next(int min, int max)
Parameters
Type Name Description
int min
int max
Returns
Type Description
int
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.

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
ObjectExtensions.AssignByReflection<T>(T, T)
ObjectExtensions.GraphCopy<T>(T)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top