CounterBasedRandomSource<TGenerator, TWord>.SetCounter Method

Sets the counter to the specified value.

Definition

Namespace: Numerics.NET.Random
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.3.0
C#
public void SetCounter(
	ReadOnlySpan<TWord> counter
)

Parameters

counter  ReadOnlySpan<TWord>
The new counter value. Length must exactly match CounterLength.

Implements

ICounterBased<T>.SetCounter(ReadOnlySpan<T>)

Remarks

Setting the counter moves the generator to a specific position in the output sequence. This enables O(1) skip-ahead to arbitrary positions.

Consistency Protocol:

After calling SetCounter(ReadOnlySpan<T>), the engine enters an inconsistent state where the cached block does not correspond to the current key/counter coordinates. Callers must invoke GenerateBlock() before using any output mapping methods (Output(Int32) or Fill(Int32, Span<T>)). Invoking output methods while inconsistent results in undefined behavior.

Exceptions

ArgumentException Thrown when counter.Length != CounterLength.

See Also