Random 6 Digit Number Generator

Six-digit values for test OTPs and sample record IDs. Allow leading zeros when every code has to be exactly six characters wide.

Why six digits specifically

Six digits is the near-universal length for a one-time passcode, and the reason is a balance between two failure modes. A million possible values is enough that guessing one within the short window before it expires is impractical, especially with rate limiting. It is also short enough to be read from a screen, held in working memory and typed into another device without an error. Four digits would be guessable within a typical validity window; eight would be reliably mistyped. Reference numbers and booking codes settle on the same length for the same reason.

Leading zeros matter more than they look

The toggle for leading zeros is not cosmetic. If codes are generated as numbers between 0 and 999999, roughly one in ten falls below 100000 and renders with fewer than six digits unless it is padded. Systems that store the code as an integer and compare it as a string will then fail to match 042381 against 42381, a bug that appears in about ten percent of cases, which is frequent enough to be reported and rare enough to be hard to reproduce. Generating with padding on lets you produce exactly that case deliberately and test it.

Frequently asked questions

Why would I want leading zeros?

To test the case where a code stored as an integer loses its leading zero and no longer matches as a string, a bug that hits roughly one code in ten.

Are these safe to use as real verification codes?

No. Real codes need a cryptographic random source, single use and short expiry. These are for test fixtures and sample data.

Can the same number appear twice?

Yes. Each value is drawn independently, so repeats are possible in a long list, as they would be in real generated codes.