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.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill generate-unique-random-numbers-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.1 KB, 326 tokens by cl100k_base, as published. Nobody here has run it
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
- Use
crypto.getRandomValuesto generate the base random number. - Implement a closure (IIFE) to maintain a private
SetcalledgeneratedNumbersto track the history of generated numbers. - The generator function must return a number within the desired range (e.g., between a minimum and maximum value).
- Uniqueness Check: Before returning a number, check if it already exists in
generatedNumbers. If it does, regenerate until a unique number is found. - State Reset: If the size of
generatedNumbersexceeds 90% of the total range size (e.g.,0.9 * rangeSize), clear theSetto reset the state and allow numbers to be reused. - 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
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.