Struct SplitMix64RNG
A SplitMix64 random number generator. Extremely fast with minimal 64-bit state, best suited for quick seeding, hash-like randomness, and procedural pipelines.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Random
Assembly: ScyllaCore.dll
Syntax
[Serializable]
public struct SplitMix64RNG : IRandomSource
Remarks
SplitMix64 (Steele et al.) is a simple, fast PRNG with:
- 64-bit internal state - the smallest of all Scylla RNG algorithms
- Period of 2^64
- Excellent bit diffusion (avalanche effect) via a bijective mixing function
- Very fast generation with only a few multiply and XOR-shift operations
Best suited for:
- Seeding other RNG algorithms from a single integer seed
- Procedural pipelines where compact state and speed matter most
- Generating independent stream IDs or hash-like random values
For long sequences where statistical quality is critical, prefer Xoshiro256StarStar or PCG32. SplitMix64 is also used internally by RandomSeeder to expand seeds for other algorithms.
The generator is a value type (struct) with an 8-byte footprint. Be aware
that assigning a SplitMix64RNG value copies its state; two copies
seeded identically will produce the same sequence.
State can be captured and restored with GetState() and SetState(SplitMix64State), enabling deterministic replay and save/load functionality.
Methods
FromSeed(int)
Creates a SplitMix64 RNG from the specified 32-bit signed seed value. The value is zero-extended to 64 bits before use.
Declaration
public static SplitMix64RNG FromSeed(int seed)
Parameters
| Type | Name | Description |
|---|---|---|
| int | seed | The 32-bit signed seed. It is reinterpreted as a 32-bit unsigned integer and then widened to 64 bits, so negative values map to the upper half of the 64-bit unsigned range. |
Returns
| Type | Description |
|---|---|
| SplitMix64RNG | A fully initialized SplitMix64RNG instance. |
FromSeed(long)
Creates a SplitMix64 RNG from the specified 64-bit signed seed value. The value is reinterpreted as an unsigned 64-bit integer.
Declaration
public static SplitMix64RNG FromSeed(long seed)
Parameters
| Type | Name | Description |
|---|---|---|
| long | seed | The 64-bit signed seed. It is reinterpreted bit-for-bit as a |
Returns
| Type | Description |
|---|---|
| SplitMix64RNG | A fully initialized SplitMix64RNG instance. |
FromSeed(uint)
Creates a SplitMix64 RNG from the specified 32-bit unsigned seed value. The value is widened to 64 bits before use.
Declaration
public static SplitMix64RNG FromSeed(uint seed)
Parameters
| Type | Name | Description |
|---|---|---|
| uint | seed | The 32-bit unsigned seed value. |
Returns
| Type | Description |
|---|---|
| SplitMix64RNG | A fully initialized SplitMix64RNG instance. |
FromSeed(ulong)
Creates a SplitMix64 RNG using the specified 64-bit unsigned seed value. The seed is used directly as the initial state - the first call to NextUInt64() will increment the state before mixing, so no additional warm-up is needed.
Declaration
public static SplitMix64RNG FromSeed(ulong seed)
Parameters
| Type | Name | Description |
|---|---|---|
| ulong | seed | The seed value used as the initial 64-bit state. All seed values, including zero, produce valid, non-degenerate sequences. |
Returns
| Type | Description |
|---|---|
| SplitMix64RNG | A fully initialized SplitMix64RNG instance. |
FromString(string)
Creates a SplitMix64 RNG from a stable hash of the given string. The string is hashed using FNV-1a to produce a reproducible 64-bit seed, making this useful for named procedural seeds (e.g., level names, world IDs).
Declaration
public static SplitMix64RNG FromString(string seed)
Parameters
| Type | Name | Description |
|---|---|---|
| string | seed | The string used to generate a stable, cross-platform seed hash. The same string always produces the same RNG sequence on any platform. |
Returns
| Type | Description |
|---|---|
| SplitMix64RNG | A fully initialized SplitMix64RNG instance. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
GetState()
Retrieves the current internal state of the RNG for serialization or checkpointing.
Declaration
public SplitMix64State GetState()
Returns
| Type | Description |
|---|---|
| SplitMix64State | A SplitMix64State struct containing the current 64-bit state value. Restoring this snapshot via SetState(SplitMix64State) will reproduce the exact same sequence of values from this point forward. |
NextBytes(byte[], int, int)
Fills a specified portion of a byte array with random bytes generated by the SplitMix64 algorithm.
Declaration
public void NextBytes(byte[] buffer, int offset = 0, int count = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | buffer | The byte array to populate. Must not be |
| int | offset | The zero-based index in |
| int | count | The number of bytes to write starting at |
Remarks
Each call to NextUInt64() produces 8 bytes written in little-endian order (least-significant byte first). Any unused bytes from the final 64-bit draw are discarded.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
| ArgumentOutOfRangeException | Thrown when |
NextUInt32()
Returns an unsigned 32-bit random value derived from the upper 32 bits of a full 64-bit SplitMix64 output.
Declaration
public uint NextUInt32()
Returns
| Type | Description |
|---|---|
| uint | A uniformly distributed unsigned 32-bit integer in the range
[ |
Remarks
Calls NextUInt64() internally and shifts the result right by 32 bits to extract the high word. Using the upper bits is recommended because SplitMix64 (like most linear generators) has slightly weaker lower-bit quality; however, this is generally negligible in practice. One full 64-bit SplitMix64 step is consumed per call regardless.
NextUInt64()
Returns an unsigned 64-bit random value using the SplitMix64 algorithm.
Declaration
public ulong NextUInt64()
Returns
| Type | Description |
|---|---|
| ulong | A uniformly distributed unsigned 64-bit integer in the range
[ |
Remarks
Delegates to SplitMix64Next(ref ulong), which increments
_state by the golden-ratio constant 0x9E3779B97F4A7C15 and then
applies the bijective SplitMix64 mixing function (two multiply-XOR-shift rounds)
to produce the output.
All 64 output bits are of equal quality. The mixing function provides excellent avalanche properties: a 1-bit change in state propagates to all output bits.
SetState(SplitMix64State)
Restores the RNG to a previously saved state, enabling deterministic replay from a known checkpoint.
Declaration
public void SetState(SplitMix64State state)
Parameters
| Type | Name | Description |
|---|---|---|
| SplitMix64State | state | The state snapshot to restore. Any 64-bit value in State is valid and will produce a well-behaved sequence. |