AutoSkill 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.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/generate-unique-random-numbers-with-state-reset" ~/.claude/skills/ecnu-icalk-autoskill-generate-unique-random-numbers-with-state-reset && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/generate-unique-random-numbers-with-state-reset/SKILL.mdsource content
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
to generate the base random number.crypto.getRandomValues - Implement a closure (IIFE) to maintain a private
calledSet
to track the history of generated numbers.generatedNumbers - 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
. If it does, regenerate until a unique number is found.generatedNumbers - State Reset: If the size of
exceeds 90% of the total range size (e.g.,generatedNumbers
), clear the0.9 * rangeSize
to reset the state and allow numbers to be reused.Set - 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