Stop typing random digits
Storybook needs twelve unique stock values between 1 and 50—hand-rolling numbers duplicates and wastes time. Console Math.random() still needs scaling, flooring, and careful JSON commas.
Random Number emits inclusive integers only: min, max, count, optional unique draws inside the range. Output is comma-separated for quick array paste.
Versus Mock Test Data: mock rows ship person-shaped fields; this page ships plain integer lists you map into your schema.
What the component implements
Three fields map to min, max, count; generate uses parseInt and surfaces invalidNumber from toolCommon on bad input.
min > max → minGtMax. Count must be 1–1000 (countRange).
With unique checked, the range must fit at least count distinct integers (notEnoughUnique). Values use Math.floor(Math.random() * (hi - lo + 1)) + lo with resampling on collision.
Runs entirely client-side—still Math.random, not cryptographically secure.
The output field lists every draw separated by commas; copy the block as-is when you only need a quick list, or split on commas inside your editor.
Wire with mock JSON and UUIDs
See mock JSON without an API for person fields; use this tool for stockQty, pageIndex, etc.
For string IDs see UUID v4 mocks—integer IDs may clash with production autoincrement; label staging fakes.
Wrap comma output in JSON Formatter as "values": [ … ].
In component tests, paste the comma line into an array literal once, commit the fixture, and stop re-rolling on every save—randomness belongs in the generator step, not in snapshot diffs.
Flow (figure)
Habit: count=5 to validate the range → confirm unique mode fits → scale to full batch.
Validation errors (figure)
Unique + narrow range: widen max-min or disable unique.
Need decimals: not supported here—use spreadsheets or app code.
Limits
Integers in a closed range only—no decimals, weights, or fixed seeds (reload changes the sequence).
Not for compliance draws, tokens, or session IDs—use server-side CSPRNG.
Cap 1000 numbers per click; bigger sets belong in scripts or DB seeds.
Negative bounds work if you type them—the same parseInt and range math apply, but most API mocks stick to non-negative counters.
FAQ
QInclusive max?
AYes—1–100 includes both ends, matching RandomNumber.tsx.
QCSV export?
ACopy the comma line into Excel split columns, or merge into your JSON.
QOverlap with Mock Data?
AMock does not emit random integer lists; this tool does not emit names or phones—use both.
QSame sequence every refresh?
ANo—Math.random is not seeded. Freeze values in your repo after you generate once.
Worked example (step by step)
1. A pagination story needs ten unique page indices from 1–200.
2. Random Number: min 1, max 200, count 10, unique on, generate.
3. Paste into Pagination.stories.tsx mock props.
4. If notEnoughUnique fires, verify count is not larger than the range width.
5. Wrap with JSON Formatter as { "pages": […] } for MSW.
6. Pair with a UUID Generator requestId in the same mock row.
Copy-paste snippet
Paste generated integers into a handler fixture:
{
"stockQty": [12, 45, 3, 50, 17]
}Replace numbers with your run; rename fields to match the API contract.