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
minValueintThe inclusive lower bound of the random number returned.
maxValueintThe exclusive upper bound of the random number returned.
maxValuemust be greater than or equal tominValue.
Returns
- int
A 32-bit signed integer greater than or equal to
minValueand less thanmaxValue; that is, the range of return values includesminValuebut notmaxValue. IfminValueequalsmaxValue,minValueis returned.
Exceptions
- ArgumentOutOfRangeException
minValueis greater thanmaxValue.
NextBytes(byte[])
Fills the elements of a specified array of bytes with random numbers.
public override void NextBytes(byte[] buffer)
Parameters
bufferbyte[]The array to be filled with random numbers.
Exceptions
- ArgumentNullException
bufferis 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.