NasrTech

Random PIN Generator: 4, 6 or 8 Digits

A new PIN is waiting below. Press 4, 6 or 8 digits (or slide to any length up to 12) and copy it. Every digit is drawn with crypto.getRandomValues, and easy guesses such as 0000 and 1234 are skipped unless you switch that off.

Your PIN

Each digit comes from your browser's cryptographically secure random generator. Nothing is sent or stored.

—
Length
6

How to generate a random PIN

1

Pick the length

Press 4, 6 or 8 digits, or drag the slider for any length from 4 to 12. A PIN appears straight away.

2

Decide about easy guesses

With the switch on, the generator never returns a single repeated digit such as 0000 or a straight run such as 1234 or 4321. Turn it off if every code must be possible.

3

Copy it

Press the copy button, or the arrows for another PIN. The line under the code shows how many different codes that length allows.

How the PINs are made

The generator is short enough to describe line by line. For each digit, the page asks crypto.getRandomValues, the browser's cryptographically secure random source, for one 32-bit number between 0 and 4,294,967,295. If the number is 4,294,967,290 or higher, it is thrown away and a fresh one is drawn. Otherwise the digit is the remainder after dividing by 10.

Throwing away the top six values keeps the digits fair: the 4,294,967,290 numbers that remain split into exactly 429,496,729 for each digit from 0 to 9, so no digit comes up more often than another. Math.random, the browser's ordinary random function, is not used anywhere in the generator.

With Skip easy guesses on, the finished PIN gets one check. If every digit is the same, or the digits climb or fall by one at each step, the whole PIN is drawn again. Random does not mean it can't be 1234: without the check, a 4-digit generator returns one of these 24 codes about once in 400 tries. They are the first codes anyone types, so the switch is on by default.

The PIN never leaves the page. The generator makes no network request and saves nothing, so a reload gives you a different code.

How hard is a random PIN to guess?

The odds that someone who knows nothing about your PIN hits it within a fixed number of tries. Code counts are the ones the tool shows with Skip easy guesses on.

LengthPossible codesChance in 10 triesChance in 100 tries
4 digits9,976about 1 in 1,000 (0.1%)about 1 in 100 (1%)
6 digits999,9801 in 100,000 (0.001%)1 in 10,000 (0.01%)
8 digits99,999,9841 in 10 million1 in 1 million

These odds hold only because the PIN is random. A PIN you choose yourself is far easier to guess.

Choosing and using a PIN safely

People pick PINs in patterns, and that matters more than length. In a study of 1,220 PINs chosen for unlocking a phone, Markert and colleagues (IEEE Symposium on Security and Privacy, 2020) found that 6-digit PINs gave little or no extra protection over 4-digit ones against an attacker allowed 10, 30 or 100 guesses. They also found that the small blocklists iOS used for “easy” PINs gave little or no benefit. A random PIN sidesteps both problems, because every code is equally likely.

  • Use the longest PIN the lock accepts. With a random PIN, every extra digit cuts the odds in the table above by ten.
  • Use a separate PIN for each card, phone and SIM. One leaked code then opens one thing, not all of them.
  • Keep it away from anything personal, such as a birth year or part of your phone number. A generated PIN has no link to you by design.
  • Rely on the attempt limit. A PIN is safe only where the lock blocks or wipes after a few wrong tries, as phones and bank cards do. Where nothing limits attempts, a 4- or 6-digit code falls quickly, so use the strong password generator instead.
  • Don't store it with the thing it unlocks. A PIN written on the card or saved in a note on the same phone protects nothing.

Frequently asked questions

What length should my PIN be?

Use the longest the system accepts. Four digits give 10,000 possible codes, six give 1,000,000 and eight give 100,000,000.

Are the PINs truly random?

Yes. Every digit comes from the browser's cryptographically secure random source, and each of the ten digits is equally likely. With “Skip easy guesses” on, a PIN made of one repeated digit or a straight run is discarded and drawn again.

Which PINs does “Skip easy guesses” remove?

Codes made of a single repeated digit, such as 0000 or 777777, and straight ascending or descending runs, such as 1234, 4321 or 456789. For four digits that is 24 codes out of 10,000.

Is a numeric PIN as strong as a password?

No. A digits-only PIN has far fewer combinations than a password with letters and symbols. Use it where a numeric code is required and the number of attempts is limited, and prefer a full password otherwise.

Does the generator use Math.random?

No. Every digit comes from crypto.getRandomValues, the Web Crypto source browsers provide for security work. Math.random is not called anywhere in the generator.

Is the PIN uploaded anywhere?

No. It is generated in your browser and is never sent or stored by the tool.

Related tools