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
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
Methods
Next()
Returns a non-negative random integer.
public override int Next()
Returns
Next(int, int)
Returns a random integer that is within a specified range.
public override int Next(int minValue, int maxValue)
Parameters
minValue
intThe inclusive lower bound of the random number returned.
maxValue
intThe exclusive upper bound of the random number returned.
maxValue
must be greater than or equal tominValue
.
Returns
- int
A 32-bit signed integer greater than or equal to
minValue
and less thanmaxValue
; that is, the range of return values includesminValue
but notmaxValue
. IfminValue
equalsmaxValue
,minValue
is returned.
Exceptions
- ArgumentOutOfRangeException
minValue
is greater thanmaxValue
.
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
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.