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-6/

Shared Stream Random Sequences

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.

Capabilities

Stream continuity across calls and iteration

  • Calling 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. @test

Iterable batches reuse stream state

  • Two successive take(2) calls return four numbers without restarting or skipping, continuing one shared sequence. @test

Bound-respecting emissions

  • Every emitted number is within the inclusive [minimum, maximum] range even when mixing next() and take(). @test

No immediate repeats

  • No consecutive numbers in the combined emission order are identical, regardless of whether they came from direct calls or iteration. @test

Implementation

@generates

API

export type SharedRandom = {
  next(): number;
  take(count: number): number[];
};

export function createSharedRandom(minimum: number, maximum: number): SharedRandom;

Dependencies { .dependencies }

unique-random { .dependency }

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

tile.json