Generate random numbers that are consecutively unique
90
Build a helper that surfaces a non-repeating, random rotation over a provided list of IDs. The rotator must allow both callable access and iteration over the same underlying stream.
next() calls always return different IDs while staying within the provided list. @testfor...of loop yields the same sequence as chained next() calls, consuming shared state so interleaving the two never produces back-to-back duplicates. @testsequence(count) returns the next count IDs in order, with no consecutive duplicates, and subsequent next() continues from where sequence left off. @testnext(), iteration, and sequence always return that lone value. @test@generates
export interface IdRotator extends Iterable<string> {
next(): string;
sequence(count: number): string[];
[Symbol.iterator](): Iterator<string>;
}
export function createIdRotator(ids: string[]): IdRotator;Provides consecutively unique random value generation for bounded ranges.
Install with Tessl CLI
npx tessl i tessl/npm-unique-random