Generate random numbers that are consecutively unique
90
Implement a shared random stream facility that exposes both direct calls and iterable batches from the same underlying source. Iterating over the shared generator (for example with for...of) must yield the same sequence as successive direct calls.
next() twice and then take(3) returns five numbers where take continues the same stream rather than restarting; take gathers its numbers by iterating the shared source. @testtake(2) calls return four numbers without restarting or skipping, continuing one shared sequence. @test[minimum, maximum] range even when mixing next() and take(). @test@generates
export type SharedRandom = {
next(): number;
take(count: number): number[];
};
export function createSharedRandom(minimum: number, maximum: number): SharedRandom;Use the package's callable-and-iterable random generator to back the shared stream without reimplementing stream logic.
Install with Tessl CLI
npx tessl i tessl/npm-unique-random