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: 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

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