RandomStreamPartition<TRandom> Class

Implements hierarchical random stream generation using jump-based partitioning.

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public sealed class RandomStreamPartition<TRandom> : RandomStreamSource<TRandom>
where TRandom : Object, IJumpable, IRandomSourceFactory<TRandom>
Inheritance
Object  →  RandomStreamSource<TRandom>  →  RandomStreamPartition<TRandom>

Type Parameters

TRandom
The type of random number generator to produce. Must implement IJumpable.

Remarks

RandomStreamPartition<TRandom> provides RngStreams-style stream partitioning where streams are created by jumping forward along a single sequence. This approach:

  • Partitions a sequence: Each stream continues from where the previous left off
  • Requires jumping: Only works with RNGs that implement IJumpable
  • O(N) enumeration: Generating N streams requires N jump operations
  • Supports hierarchical partitioning: Different strides at different levels

Cursor-Based Incremental Enumeration:

Unlike mixing-based streams, jump-based partitioning maintains an internal cursor RNG that tracks the current position in the sequence. Each call to NextStream() returns a copy of the cursor, then advances it by one stride. This ensures O(N) total cost for N streams, not O(N²).

Stride Control:

The Stride property controls the spacing between streams:

  • Jump: Standard jump distance (e.g., 2^128 for Xoshiro256)
  • LongJump: Extended jump distance (e.g., 2^192 for Xoshiro256)

Hierarchical Partitioning:

Different strides can be used at different hierarchy levels to create two-level partitioning schemes similar to RngStreams:

// Level 1: Processes (LongJump) var processes = new RandomStreamPartition<Xoshiro256>( options, JumpStride.LongJump); // Level 2: Threads within a process (Jump) var process0 = processes.Branch(0, JumpStride.Jump); var thread0 = process0.NextStream(); var thread1 = process0.NextStream();

Path Interpretation:

Each element in the path represents a number of stride jumps from the anchor point. For example, path [2, 3] with Jump stride means:

  1. Start from base options
  2. Jump 2 times (level 1)
  3. Jump 3 times (level 2)

Example

C#
var options = new RandomOptions(42);

// Create partition with standard jump stride
var partition = new RandomStreamPartition<Xoshiro256StarStar>(
    in options, JumpStride.Jump);

// Generate streams incrementally (O(N) total)
var rng0 = partition.NextStream();
var rng1 = partition.NextStream();
var rng2 = partition.NextStream();

// Create child partition with different stride
var child = partition.Branch(5, JumpStride.Jump);
var childRng0 = child.NextStream();

Constructors

RandomStreamPartition<TRandom> Initializes a new instance of the RandomStreamPartition<TRandom> class.

Properties

NextIndex Gets the index of the next stream to be consumed at this scope.
(Inherited from RandomStreamSource<TRandom>)
Path Gets the hierarchical path identifying the current scope.
(Inherited from RandomStreamSource<TRandom>)
Stride Gets the jump stride used at this hierarchy level.

Methods

Advance Advances the next index by the specified count without generating streams.
(Overrides RandomStreamSource<TRandom>.Advance(UInt64))
Branch(UInt64) Creates a child stream source at the specified index without advancing this source.
(Inherited from RandomStreamSource<TRandom>)
Branch(UInt64, JumpStride) Creates a child stream source at the specified index with a specific stride.
BranchAndAdvance Creates a child stream source at the current next index and advances this source.
(Inherited from RandomStreamSource<TRandom>)
EqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
GetHashCodeServes as the default hash function.
(Inherited from Object)
GetTypeGets the Type of the current instance.
(Inherited from Object)
NextStream Returns an RNG for the next child stream and advances the index.
(Overrides RandomStreamSource<TRandom>.NextStream())
NextStreams(Int32) Returns an array of RNGs for the next N child streams and advances the index.
(Inherited from RandomStreamSource<TRandom>)
NextStreams(Span<TRandom>) Fills the specified span with the next child streams and advances the index.
(Inherited from RandomStreamSource<TRandom>)
PrefixStream Returns an RNG corresponding to the current path prefix only.
(Overrides RandomStreamSource<TRandom>.PrefixStream())
Seek Sets the next stream index to the specified value.
(Overrides RandomStreamSource<TRandom>.Seek(UInt64))
ToStringReturns a string that represents the current object.
(Inherited from Object)

See Also