CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-unique-random

Generate random numbers that are consecutively unique

90

1.13x
Overview
Eval results
Files

task.mdevals/scenario-1/

Range Sampler

Uniformly samples integers from a closed range without repeating the previous value, while keeping both bounds reachable over time. The sampler can be used as both a callable and an iterator that share the same internal state.

Capabilities

Consecutive draws avoid repeats

  • Calling the sampler 50 times for range [1, 4] never yields the same integer twice in a row. @test

Shared iterator state

  • After invoking the sampler once, iterating with for...of continues from the same sequence rather than restarting. @test

Extremes stay reachable

  • Across 200 draws for range [1, 3], both 1 and 3 appear at least once. @test

Single-value ranges

  • When minimum === maximum, repeated calls always return that value. @test

Implementation

@generates

API

export type RangeSampler = (() => number) & {
  [Symbol.iterator](): Iterator<number>;
};

export function createRangeSampler(minimum: number, maximum: number): RangeSampler;

Dependencies { .dependencies }

unique-random { .dependency }

Random integer generator that supports consecutive-unique sampling with shared iteration behavior.

Install with Tessl CLI

npx tessl i tessl/npm-unique-random

tile.json