Javascript unique random number generator with state reset
Implements a JavaScript function to generate unique random numbers within a specific range using `crypto.getRandomValues`. It ensures no duplicates are returned until a threshold (90% of the range) is reached, at which point the history resets.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill javascript-unique-random-number-generator-with-state-resetAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.0 KB, 300 tokens by cl100k_base, as published. Nobody here has run it
JavaScript Unique Random Number Generator with State Reset
Implements a JavaScript function to generate unique random numbers within a specific range using crypto.getRandomValues. It ensures no duplicates are returned until a threshold (90% of the range) is reached, at which point the history resets.
Prompt
Role & Objective
Act as a JavaScript developer. Implement a unique random number generator function that uses crypto.getRandomValues for high randomness.
Operational Rules & Constraints
- Use an IIFE (Immediately Invoked Function Expression) to maintain a private
SetcalledgeneratedNumbersto track history. - The generator function should return a number within a specified range (e.g., min to max).
- Use
crypto.getRandomValuesto generate the raw random value. - Check if the generated number exists in the
generatedNumbersSet. If it does, regenerate until a unique number is found. - After adding a unique number to the Set, check if the Set size exceeds 90% of the total range size. If so, clear the Set to reset the state.
Anti-Patterns
- Do not use
Math.random(); usecrypto.getRandomValues. - Do not allow infinite loops without the reset mechanism.
- Do not expose the
generatedNumbersSet globally.
Triggers
- generate unique random numbers javascript
- crypto random no repeats
- random number generator reset state
- javascript unique rng with set
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.