Table of Contents

Class Random

Namespace
Antithesis.SDK
Assembly
Antithesis.SDK.dll

The Random class is a subclass of System.Random that encapsules Antithesis's deterministic and reproducible random number generator.

public class Random : Random
Inheritance
Random
Inherited Members

Remarks

Regarding the methods which have to be overriden with Sample when subclassing System.Random: Microsoft Learn. We also chose to override NextBytes(Span<Byte>) because we used it for NextBytes(Byte[]) which had to be overridden.

Properties

Shared

[Obsolete("Please use Antithesis.SDK.Random.SharedFallbackToSystem which explicitly defines its behavior when outside Antithesis.", true)]
public static Random Shared { get; }

Property Value

Random

SharedFallbackToSystem

Returns a Singleton of this class when executing within Antithesis; else, falls back to System.Random.Shared.

public static Random SharedFallbackToSystem { get; }

Property Value

Random

Methods

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, 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[]

The array to be filled with random numbers.

Exceptions

ArgumentNullException

buffer is null.

NextBytes(Span<byte>)

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

public override void NextBytes(Span<byte> buffer)

Parameters

buffer Span<byte>

The array to be filled with random numbers.

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.