flashman
← All guides

Generate a UUID batch from a count that is a number

Generate local version 4 UUID batches from the count field: blank values clamp to one id, decimals truncate, and a non-numeric count prints an empty list.

2026-10-20 · 7 min read

  • uuid
  • fixtures
  • tooling

The UUID page fills a list by calling crypto.randomUUID() once per line. The ids are version 4. The count field is a number input whose value is passed through Number(), clamped with Math.min and Math.max, and then used as an array length. The page does not show a separate error when that length is zero.

Decide how many ids you need, type an integer from 1 to 100, and copy the list before you edit the count again. The next edit mints a new batch.

Read the clamp before you count lines

The clamp is Math.max(1, Math.min(100, Number(value))). A blank field is 0 and becomes 1. 0 and -3 become 1. 101 becomes 100. 1e2 becomes 100. Infinity becomes 100. A padded " 3 " becomes 3 because Number() allows surrounding spaces.

20.9 is still 20.9 after the clamp, because 20.9 is inside 1 and 100. Array.from then converts the length with the integer rule and prints 20 lines. The fraction is discarded at that step, not by the clamp.

  • Type an integer when you need an exact batch size.
  • Expect one id from a cleared field.
  • Expect 100 ids from any finite count above 100.
  • Expect 20 ids from 20.9.

A letter produces an empty list

"abc" and the text NaN both become NaN. Math.min(100, NaN) is NaN, and Math.max(1, NaN) is NaN, so the clamp does not save you. Array.from({ length: NaN }) has length 0. The page shows an empty pre. There is no Error line. Copy has an empty string until the count is numeric again.

That empty list is a count problem. It is not evidence that crypto.randomUUID() failed. Delete the letter and the list returns.

Treat the lines as a disposable fixture

Each count change builds a new list. The previous ids are gone. Copy writes the current lines separated by newlines. The third group of each id starts with 4. A version 7 id, whose third group starts with 7, was not minted here.

Use these ids in fixtures, logs you are willing to throw away, and local requests. They are not a secret store, and the timestamp in a version 7 id is a different layout.

Check the version when the id came from elsewhere

Use the UUID tool for a version 4 batch, diff to prove two snapshots differ, the JSON formatter when the id sits in a payload, and the timestamp tool on the first twelve hex digits of a version 7 id. Write the count you typed next to the batch, especially when the field contained a letter or a decimal.

Try these tools