Table of Contents

Class DeterministicRandom

Namespace
Temporalio.Common
Assembly
Temporalio.dll

Implementation of Random that is deterministic and supports a 64-bit seed, unlike the standard implementation which is only 32-bit. Internally this uses a well-known/tested PCG-based algorithm (specifically, 128-bit MCG PCG-XSL-RR aka pcg64_fast), see https://www.pcg-random.org/. Changing of this internal algorithm in any way is considered a backwards incompatible alteration.

public class DeterministicRandom : Random
Inheritance
DeterministicRandom
Inherited Members

Constructors

DeterministicRandom(ulong)

Initializes a new instance of the DeterministicRandom class.

public DeterministicRandom(ulong seed)

Parameters

seed ulong

Seed for this random.

Methods

~DeterministicRandom()

Finalizes an instance of the DeterministicRandom class.

protected ~DeterministicRandom()

Next()

Returns a non-negative random integer.

public override int Next()

Returns

int

A 32-bit signed integer that is greater than or equal to 0 and less than MaxValue.

Next(int)

Returns a non-negative random integer that is less than the specified maximum.

public override int Next(int maxValue)

Parameters

maxValue int

The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to 0.

Returns

int

A 32-bit signed integer that is greater than or equal to 0, and less than maxValue; that is, the range of return values ordinarily includes 0 but not maxValue. However, if maxValue equals 0, maxValue is returned.

Exceptions

ArgumentOutOfRangeException

maxValue is less than 0.

Next(int, int)

Returns a random integer that is within a specified range.

public override int Next(int minValue, int maxValue)

Parameters

minValue int

The inclusive lower bound of the random number returned.

maxValue int

The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue.

Returns

int

A 32-bit signed integer greater than or equal to minValue and less than maxValue; that is, the range of return values includes minValue but not maxValue. If minValue equals maxValue, minValue is returned.

Exceptions

ArgumentOutOfRangeException

minValue is greater than maxValue.

NextBytes(byte[])

Fills the elements of a specified array of bytes with random numbers.

public override void NextBytes(byte[] buffer)

Parameters

buffer byte[]

An array of bytes to contain random numbers.

Exceptions

ArgumentNullException

buffer is null.

NextDouble()

Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0.

public override double NextDouble()

Returns

double

A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0.

Sample()

Returns a random floating-point number between 0.0 and 1.0.

protected override double Sample()

Returns

double

A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0.