Random Stream Partition<TRandom> Class
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
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:
- Start from base options
- Jump 2 times (level 1)
- Jump 3 times (level 2)
Example
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
| Random | Initializes a new instance of the RandomStreamPartition<TRandom> class. |
Properties
| Next |
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( |
Creates a child stream source at the specified index without advancing this source.
(Inherited from RandomStreamSource<TRandom>) |
| Branch( | Creates a child stream source at the specified index with a specific stride. |
| Branch |
Creates a child stream source at the current next index and advances this source.
(Inherited from RandomStreamSource<TRandom>) |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Get | Serves as the default hash function. (Inherited from Object) |
| Get | Gets the Type of the current instance. (Inherited from Object) |
| Next |
Returns an RNG for the next child stream and advances the index.
(Overrides RandomStreamSource<TRandom>.NextStream()) |
| Next |
Returns an array of RNGs for the next N child streams and advances the index.
(Inherited from RandomStreamSource<TRandom>) |
| Next |
Fills the specified span with the next child streams and advances the index.
(Inherited from RandomStreamSource<TRandom>) |
| Prefix |
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)) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |