PIN generator

Generate random numeric PINs of 3 to 16 digits with the secure random generator of your browser, with no bias between digits.

loading PIN generator
About this tool

What is a PIN generator?

A PIN is a short numeric secret: the code of a bank card, a phone lock, a SIM card, a door keypad, a voicemail box. Because it has only digits, it is easy to type and easy to guess. A four-digit PIN has just 10000 possibilities, and people make it worse by choosing birthdays, years and patterns such as 1234 or 0000.

This tool draws PINs of 3 to 16 digits with the secure random generator of your browser. Each digit is chosen with the same probability. The code reads random bytes and discards the ones from 250 to 255, so the remainder of dividing by ten does not favour the digits 0 to 5. Nothing is sent or stored, and you can ask for up to 200 PINs at once.

It has two optional filters. Skip easy PINs removes the PINs attackers try first: all the same digit (1111, 000000), straight runs up or down (1234, 4321, 9876), PINs made of a repeated half (1212, 123123) and a short list of the most common four-digit PINs (1234, 1111, 0000, 1212, 7777, 1004, 2000, 4444, 2222, 6969 and a few more). No repeated digit makes every digit different, which is useful for some keypads but reduces the number of possibilities: a four-digit PIN with no repeats has 5040 options, not 10000.

Be honest about what a PIN can do. A short number is weak by itself. It protects only when the system limits the guesses: a card that blocks after three wrong tries, a phone that waits longer after each failure, a device that wipes after ten. If an attacker can copy the data and try codes offline at full speed, any PIN falls in seconds. For that case use a long passphrase, such as one from the Diceware generator.

How to generate a PIN

  1. Set Digits: from 3 to 16. Four and six are the usual sizes; choose six or more when the system allows it.
  2. Set How many: if you want several to choose from or to hand out, for example one per device.
  3. Leave Skip easy PINs ticked unless you need every possible PIN, such as when making test data.
  4. Tick No repeated digit only if the keypad or the rules demand it.
  5. Click Generate again for a new set. The PINs list shows the codes, and the line under it shows the bits of randomness per PIN.
  6. Use Copy all to copy the list, one PIN per line.

Examples

How the digits are drawn

Suppose the random generator returns the bytes 250, 251, 255, 7, 13, 249, 0, 19 and you ask for four digits. The bytes 250, 251 and 255 are discarded because they are 250 or more. The remaining bytes 7, 13, 249, 0 become 7, 3, 9, 0. The PIN is 7390. The check in the tool's tests uses exactly these values.

What counts as easy

These are all treated as easy and skipped by default: 1111, 000000, 1234, 4321, 123456, 9876, 1212, 123123, 6969, 7777. These are not: 4827, 583920, 1357, 2580, 90210. Note that 2580 (the middle column of a keypad) passes this filter, but it is also a known pattern. If you can, take one of the random results instead of a pattern.

How strong each size is

DigitsPossibilitiesBits
410000about 13.3
61000000about 19.9
8100000000about 26.6
4, no repeats5040about 12.3

Skipping easy PINs removes only a few of the possibilities, so the line "About bits of randomness per PIN" is a very close figure either way.

Common mistakes

  • "A PIN has 3 to 16 digits." The length is outside the range. Use a number from 3 to 16.
  • "Ask for 1 to 200 PINs at a time." The count is zero, negative, fractional or above the limit.
  • "With no repeated digit the PIN can have at most 10 digits." There are only ten different digits, so a PIN of 11 digits must repeat. Untick the option or shorten the PIN.
  • Using the same PIN everywhere. If one system leaks it, all of them are open.
  • Picking a date. A birthday, an anniversary or a year is among the first guesses and is easy to find out.
  • Sharing it over chat. Treat a PIN as a password: do not send it in plain text.

Frequently asked questions

Is a random PIN better than one I choose?

Yes. People choose from a small set of memorable numbers, which attackers know from leaks. A random PIN has no pattern to exploit, so the attacker has to try the codes one by one.

Is it safe to generate a PIN in a web page?

The page works in your browser and sends nothing, so the PIN is never uploaded. Close the tab afterwards and do not leave it in a note or a chat. If the PIN protects something valuable, it is also worth asking whether you can use a longer code.

How long should a PIN be?

As long as the system allows. Four digits are acceptable when the system locks after a few tries, but six or more costs you nothing and multiplies the work by 100. For systems that do not limit tries, a PIN is not enough; use a token or a long passphrase.

Can I use it as a one-time code?

Not for sign-in codes that must be checked by a server. For time-based codes and their validation see the OTP code generator and validator.

Generate a PIN in code

JavaScript

function pin(length = 6) {
  let out = '';
  while (out.length < length) {
    for (const b of crypto.getRandomValues(new Uint8Array(length * 2))) {
      if (b < 250 && out.length < length) out += b % 10;
    }
  }
  return out;
}

Python

import secrets

pin = "".join(secrets.choice("0123456789") for _ in range(6))
Report a problem