← Back to tool

Guide · 4-digit PINs & codes

Random 4-Digit Number Generator

Updated: June 2026

A random four-digit number is the everyday building block of PINs, lockers, temporary codes and ticket stubs. Four digits feels small, but there are ten thousand of them, and the difference between a guessable PIN and a strong one comes down to two things: covering the full range including leading zeros, and using a source that can't be predicted. Here's how to get both.

Generate a 4-Digit Number →

Free · No upload · Instant in the browser

How to generate one

Set the minimum to 0 and the maximum to 9999, leave How many at 1, and generate. That gives you the full set of four-digit codes from 0000 to 9999 — ten thousand possibilities. If you specifically don't want a code that starts with a zero, set the minimum to 1000 instead, which restricts the result to 1000–9999.

PIN with leading zeros: min 0, max 9999 (10,000 options) PIN without leading zeros: min 1000, max 9999 (9,000 options)

Allowing leading zeros is the stronger choice: a four-digit code displayed as 0042 is perfectly valid and there's no reason to exclude it. Excluding the 1000 codes that start with zero only shrinks the keyspace and makes guessing slightly easier.

How strong is a 4-digit PIN?

With 10,000 possibilities, a randomly chosen 4-digit PIN has a 1 in 10,000 chance of being guessed in a single try — 0.01%. That's adequate when the number of attempts is limited, which is why phones and cards lock after a few wrong tries. It is not adequate against an attacker who can guess unlimited times quickly, because 10,000 tries is trivial for a computer.

Code lengthCombinationsOne-guess odds
4 digits10,0001 in 10,000
6 digits1,000,0001 in 1,000,000
8 digits100,000,0001 in 100,000,000

The real weakness of human-chosen PINs isn't the range — it's predictability. Codes like 1234, 0000, 1111 and birth years are wildly over-represented, so they're the first ones attackers try. A randomly generated PIN sidesteps that entirely, which is the whole reason to generate one rather than pick it yourself.

Use a crypto-secure source

For anything that protects access, switch on Crypto-secure. The default Math.random is fine for a raffle ticket, but it's pseudo-random and, in principle, predictable from its internal state. The crypto-secure option draws from crypto.getRandomValues, the browser's cryptographic generator, which produces values an attacker can't reconstruct or anticipate. For a PIN you'll actually rely on, that's the setting you want.

Generating several at once

Need codes for a batch of lockers, vouchers or test accounts? Raise How many and the tool returns that many four-digit numbers. Turn on No repeats (unique) if each code must be different — for example assigning a distinct PIN to each of 50 lockers. With 10,000 possible values you can generate thousands of unique four-digit codes before running out.

  • Temporary access PINs for lockers or doors.
  • One-time verification codes for testing flows.
  • Raffle or cloakroom ticket numbers.
  • Short reference codes for orders or bookings.

Privacy by design

Every code is generated on your own device. Nothing is uploaded, logged, or sent to a server — which matters a great deal for something like a PIN. Once the page has loaded you can even go offline and keep generating. The number exists only where you can see it.

Frequently asked questions

How do I generate a random 4-digit number?

Set the range from 0 to 9999 (or 1000 to 9999 to avoid leading zeros) and generate. There are 10,000 four-digit codes from 0000 to 9999.

How many 4-digit PINs are there?

10,000, from 0000 to 9999. A random one has a 1 in 10,000 chance of being guessed in a single try.

Should I use the crypto-secure source for a PIN?

Yes. For anything protecting access, turn it on so the PIN comes from the browser's cryptographic generator and can't be predicted.

Are leading zeros allowed?

Yes. Set the minimum to 0 and a result like 0042 is valid. Keeping leading zeros gives the full 10,000-code keyspace.