Tutorials ↗

Choosing random ID entropy and length

Derive random ID length from a 32-symbol alphabet and check grouping, collision probability and the browser implementation.

How 80 bits produce 16 random symbols in an ID

Before shortening a random ID, ask two concrete questions: how many IDs will you generate, and what collision probability can you accept? Suppose you are assigning IDs to one million imported records. With an alphabet of 32 symbols, each chosen independently and uniformly, 80 bits of random entropy require 16 random symbols. Add three hyphens and the screen shows 19 characters, while the random space still contains only 2^80 possibilities.

Open the random ID tool. Enter the requested bits and batch size to see requested entropy, actual random entropy, random symbol count and grouped display length together. This implementation connects length, the random source and collision risk so you can choose parameters for a real project.

Calculate symbols from bits

The tool uses Crockford’s fixed set of 32 encoding symbols:

0123456789ABCDEFGHJKMNPQRSTVWXYZ

Crockford’s Base 32 description lists these symbols: ten digits and 22 uppercase letters, excluding I, L, O and U. Generated IDs contain none of those letters and include no optional check symbol. Under uniform selection, one symbol carries log2(32) = 5 bits. With independent symbols, a string of L symbols has 32^L possible values and 5L bits of random entropy.

To supply at least b bits, use L = ceil(b / 5). Rounding up matters: a request for 81 bits produces 17 symbols and 85 actual random bits. The tool always generates complete five-bit symbols, so even a request for 1 bit produces 5 bits, and a request for 256 bits produces 260. Here, “actual” means the calculated output space under a uniform, independent random-source model; it is not a measurement of the device’s physical entropy.

Requested bitsRandom symbolsActual random bitsDisplay length with hyphens
1151
5151
80168019
1252512531
2565226064

The tool inserts a hyphen after every four random symbols, with a shorter final group when needed. The separator count is floor((L − 1) / 4); display length is L plus that count. Nineteen displayed characters do not mean 95 bits: three positions are fixed hyphens and add no choices.

Check an 80-bit result in the tool

In the English interface, keep Requested entropy = 80 and Batch size = 1, then click Generate IDs. The summary reports 80 requested bits, 80 actual bits, 16 random symbols and 19 grouped characters. The output contains four groups of four characters. Each new generation obtains fresh random bytes; the ID in the screenshot is the result of that particular operation.

The English tool generating an 80-bit ID with its entropy and length summary

80 bits yield 16 random symbols, displayed as 19 characters after grouping.

Change the batch size to 100, generate again and download TXT. The file contains one grouped ID per line, with the fixed filename random-ids.txt. Changing a parameter clears the old output so IDs from a previous configuration cannot be mistaken for new results. Copy or download anything you want to keep first. In this browser check, all 100 downloaded lines matched the displayed results exactly, and the 1, 5, 80, 125 and 256-bit boundary results matched the table.

These checks can reveal counting, formatting or export bugs. A sample of a hundred IDs with no duplicates cannot establish uniform randomness or global uniqueness. To assess uniformity, examine the random source and the mapping algorithm.

Why the byte mapping is unbiased

The browser fills a Uint8Array with crypto.getRandomValues. MDN describes its output as cryptographically strong random values; browsers generally use a pseudorandom generator seeded from a source with sufficient entropy. This implementation relies on that browser capability without presenting it as a measured physical true-random device.

Each output symbol uses a separate random byte. Its low five bits become the alphabet index:

const alphabet = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
const length = Math.ceil(bits / 5);
const bytes = new Uint8Array(length);
crypto.getRandomValues(bytes);
const raw = Array.from(bytes, byte => alphabet[byte & 31]).join('');
const id = raw.match(/.{1,4}/g).join('-');

This illustration omits input validation; the actual tool accepts only whole numbers from 1–256 bits and batches of 1–100 IDs. A uniform byte has 256 equally likely values. For any index k from 0 through 31, the eight values k, k+32, through k+224 map to that index. Each symbol therefore has probability 8/256 = 1/32. If the random bytes are independent, mapping each one separately also preserves symbol independence. An exhaustive check of inputs 0–255 confirms that each symbol appears exactly eight times. That verifies the mapping; the browser remains responsible for the random source.

The argument depends on an alphabet of exactly 32 symbols. With 36 symbols, byte % 36 would be biased: 256 = 7×36 + 4, giving the first four indexes eight preimages and the other 32 only seven. Changing the alphabet requires a new unbiased sampling method, such as rejecting bytes outside the largest complete multiple. The five-bit mask cannot simply be carried over.

At most, the tool requests 52×100 = 5200 random bytes in one call. If the random source is absent or throws, it clears the output and reports an explicit error, with no Math.random or server fallback. After a simulated failure and restoration of the source, the page generated IDs again. A page that has already loaded can also generate while offline; opening it for the first time still requires the webpage resources. Clipboard permissions may prevent copying, in which case you can select the text manually or download it.

Collision probability for one million 80-bit IDs

Count every generated record that could conflict in n, including records from different devices, service instances and time periods. Assuming each ID is drawn uniformly and independently from M = 2^b possible values, the exact probability of no collision is the product of (1−i/M) for i from 0 to n−1. The probability of at least one collision is one minus that product, for n≤M.

When n is small relative to the space, use the birthday approximation:

p ≈ 1 − exp(−n(n−1) / (2 × 2^b))

If x = n(n−1)/(2×2^b) is much smaller than one, p ≈ x. With n = 1,000,000 and b = 80, an independent calculation gives x = 4.135898926862076×10^-13, or about 4.14×10^-13. This is the chance of at least one matching pair in the whole million-ID batch, not a per-ID probability or a guaranteed generation capacity. For a 256-bit request, use this tool’s actual 260 bits in the model.

Conversely, under the same small-probability approximation, a total count n and an acceptable probability ε give a starting estimate of b ≥ log2(n(n−1)/(2ε)). Round up to complete five-bit symbols. For one million IDs and ε = 10^-12, the estimate is about 78.73 bits, so 16 symbols supply 80 bits. Eighty is a choice for this assumed example. A larger total, a lower risk budget or resistance to guessing requires reconsidering both the parameters and the complete security design.

A database can reject duplicates through a unique constraint, followed by regeneration and retry on conflict. Querying for an existing value before inserting still leaves a race during concurrent writes; enforce uniqueness in the system that actually accepts the write. Define the collision domain too: within one tenant or across every tenant. That changes the population counted in n and the constraint design. Random IDs reduce collision probability without guaranteeing global uniqueness.

Keep a consistent format in the receiving system

Decide whether the database stores the grouped form or the raw symbols with hyphens removed, and use the same convention at every entry point. This tool encodes only uppercase letters. If accepting manually entered IDs, you can separately normalize separators and case, but define accepted symbols and normalization rules so clients do not produce different visible forms. Hyphens aid reading and typing; they do not describe creation order. This version has no timestamp, monotonic state or cross-process ordering guarantee.

Inputs, generated results and TXT files are handled in the browser. They are not put into the page URL, retained in long-term browser storage or uploaded for computation. Loading the webpage initially requests site resources. Access analytics after deployment concern webpage visits and must not include these inputs or results. Refreshing or leaving the page loses the current output; export it to your own file if you need to retain it.

What the jet-id post establishes

The jet-id Reddit post presents the task of generating readable IDs from a target entropy. In the post body, the author states a default of 125 bits and shows CLI and API usage. The 80-bit example is labeled as 20 random characters, or 22 including hyphens; the default example is labeled as 25 random characters, or 28 including hyphens.

The 20-character 80-bit example differs from the theoretical 16-symbol length for uniform, independent selection from a 32-symbol alphabet. The reason was not verified within this work. The post’s claims about open source, shortest length, speed, timestamps and monotonic IDs remain the author’s statements; this article does not audit the license, implementation or benchmarks. Our tool independently defines its alphabet, mapping and four-symbol grouping, so its 125-bit display length is 31. It does not reproduce jet-id’s format or behavior.

For a project, record the total generation count and collision budget in the parameter decision, and the uniform independent random source and fixed format in the implementation contract. Let a unique constraint carry the receiving system’s final responsibility for rejecting duplicates. The resulting short ID then has boundaries you can check.

← Back to the list