Interface IRandomSource
Minimal random source contract used by RandomUtil helpers and extensions. All RNG algorithms and adapters implement this interface to provide a unified abstraction for generating random values, allowing callers to swap algorithms without changing downstream code.
Namespace: Scylla.Core.Util.Random
Assembly: ScyllaCore.dll
Syntax
public interface IRandomSource
Remarks
Implementations include the built-in algorithm structs (Xoshiro256StarStar, Xoroshiro128Plus, PCG32, SplitMix64RNG, MersenneTwister) and the adapter classes (CryptoRandomSource, SystemRandomSource, UnityRandomSource).
The interface intentionally exposes only the lowest-level primitives (uint,
ulong, and raw bytes). Higher-level operations such as bounded integers,
floating-point values, shuffles, and weighted picks are provided as extension methods
in RandomExtensions and static helpers in RandomUtil,
all of which accept any IRandomSource.
Thread-safety is not guaranteed by this interface. Consult the documentation of each concrete implementation to determine its thread-safety characteristics.
Methods
NextBytes(byte[], int, int)
Fills a contiguous region of a byte array with pseudo-random bytes, one byte
at a time, where each byte is independently and uniformly distributed in
[0, 255].
Declaration
void NextBytes(byte[] buffer, int offset = 0, int count = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The destination byte array. Must not be |
| int | offset | The zero-based starting index within |
| int | count | The number of bytes to fill starting at |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentOutOfRangeException | Thrown when |
NextUInt32()
Returns a uniformly distributed, unsigned 32-bit pseudo-random integer spanning
the full range [0, 2^32).
Declaration
uint NextUInt32()
Returns
| Type | Description |
|---|---|
| uint | A random uint value in the range |
NextUInt64()
Returns a uniformly distributed, unsigned 64-bit pseudo-random integer spanning
the full range [0, 2^64).
Declaration
ulong NextUInt64()
Returns
| Type | Description |
|---|---|
| ulong | A random ulong value in the range |
Remarks
Implementations that are natively 32-bit (e.g. PCG32) compose this value from two successive 32-bit draws. Implementations that are natively 64-bit (e.g. Xoshiro256StarStar) return the value directly, making this the preferred primitive for high-throughput scenarios.