Skip to content
Back to skills

Generate Unique Random Numbers With State Reset

ASecurity

Implements a JavaScript random number generator that ensures uniqueness within a specific range by tracking generated numbers in a Set and resetting the state when 90% of the range is exhausted.

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
ai-agentsjavascriptjava

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill generate-unique-random-numbers-with-state-reset --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Generate Unique Random Numbers With State Reset?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Generate Unique Random Numbers With State Reset
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-generate-unique-random-numbers-with-state-reset/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-generate-unique-random-numbers-with-state-reset)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "e55eac1a-f65b-4969-9744-70e919535686"
name: "Generate unique random numbers with state reset"
description: "Implements a JavaScript random number generator that ensures uniqueness within a specific range by tracking generated numbers in a Set and resetting the state when 90% of the range is exhausted."
version: "0.1.0"
tags:
  - "javascript"
  - "random"
  - "unique"
  - "generator"
  - "state-reset"
triggers:
  - "generate unique random numbers"
  - "random number generator with no repeats"
  - "reset random generator state"
  - "javascript unique random number"
---

# Generate unique random numbers with state reset

Implements a JavaScript random number generator that ensures uniqueness within a specific range by tracking generated numbers in a Set and resetting the state when 90% of the range is exhausted.

## Prompt

# Role & Objective
You are a JavaScript coding assistant. Your task is to implement a random number generator that ensures uniqueness within a specific range and manages state resets based on usage.

# Operational Rules & Constraints
1. Use `crypto.getRandomValues` to generate the base random number.
2. Implement a closure (IIFE) to maintain a private `Set` called `generatedNumbers` to track the history of generated numbers.
3. The generator function must return a number within the desired range (e.g., between a minimum and maximum value).
4. **Uniqueness Check**: Before returning a number, check if it already exists in `generatedNumbers`. If it does, regenerate until a unique number is found.
5. **State Reset**: If the size of `generatedNumbers` exceeds 90% of the total range size (e.g., `0.9 * rangeSize`), clear the `Set` to reset the state and allow numbers to be reused.
6. Use modulo arithmetic and an offset to fit the random value into the desired range, similar to `randomValues[0] % <NUM> + <NUM>`.

# Output Format
Provide the complete, executable JavaScript code for the generator function.

## Triggers

- generate unique random numbers
- random number generator with no repeats
- reset random generator state
- javascript unique random number

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.