# Lock Code Generator

> Generate a random lock code for a luggage, cabinet or door keypad: uniform digits, leading zeros kept, 4 to 8 digits depending on the lock.

Source: https://devplain.com/lock-code-generator/
Last updated: 2026-10-30

Generate a random lock code for a luggage, cabinet or door keypad: uniform digits, leading zeros kept, 4 to 8 digits depending on the lock.

## How It Works

A lock code generator produces the numeric secret a keypad or combination lock expects, and this page is the password generator pre-set to numbers only, four digits long — the format used by luggage locks, cabinet locks, bike locks and most door keypads.

**The digits are uniform.** Bytes come from crypto.getRandomValues, the browser's cryptographically secure generator, and are mapped to digits with rejection sampling. Because 256 is not a multiple of 10, the six byte values from 250 to 255 sit outside the last full block of 25 per digit and would otherwise over-represent the first six digits; they are discarded and redrawn instead, so each of the ten digits has exactly the same chance. Nothing is filtered: 0000, 1234 and 9999 are all as likely as any other value.

**Leading zeros are kept.** The digits are joined as text, so a code such as 0042 stays four characters instead of collapsing to 42. Locks treat the code as a sequence of digits, so a shortened code would be the wrong code.

**Choosing the length.** The page opens at four digits, which gives 10,000 combinations. Some locks accept six or eight digits, and each extra digit multiplies the space by ten: 1,000,000 for six digits and 100,000,000 for eight. Raise the length control to match the lock — it accepts any whole number from 4 to 64 — and leave it at four when the lock has exactly four dials.

**What a lock code protects.** A physical code defends against someone handling the lock, not against a remote attacker with unlimited attempts. Four digits are reasonable when the lock itself slows guessing down and the contents are replaceable; treat a code as a convenience barrier rather than as encryption, and never reuse the same code on several locks.

**Recorded nowhere.** The code is generated inside the tab, never transmitted, logged or stored. Set it on the lock, write it somewhere offline, and close the page.

### How to set a lock code

1. Check how many digits the lock accepts — four is the common case, six or eight on some keypads.
2. Set the length control to that number and confirm the character set is Numbers only.
3. Generate, then enter the code on the lock and test it once before closing the shackle or door.
4. Write the code down offline, because it cannot be recovered from this page.

### How the number of digits changes the space

| Code length | Possible codes | Typical lock |
| --- | --- | --- |
| 4 digits | 10,000 | Luggage, cabinet and most door keypads |
| 6 digits | 1,000,000 | Keypads that require a longer code |
| 8 digits | 100,000,000 | Locks and safes with an eight-digit field |

## Examples

### Input

```
Length: 4; character set: Numbers only
```

### Output

```
(4 random digits, e.g. 4821)
```

The default: a four-digit code for a luggage, cabinet or door lock.

### Input

```
Length: 4; character set: Numbers only
```

### Output

```
(4 random digits, e.g. 0042)
```

Boundary case: leading zeros. The code stays four digits long instead of collapsing to 42.

### Input

```
Length: 8; character set: Numbers only
```

### Output

```
(8 random digits, e.g. 20481537)
```

Boundary case: the longest length most locks accept, drawn from 100,000,000 possible codes.

## Frequently Asked Questions

**Can I generate a three-digit lock code?**

The length control starts at four, so a three-digit code is not produced here. Almost every combination lock uses four digits or more, and a three-digit code has only a thousand combinations. If a lock genuinely requires three digits, generate a four-digit code and set the lock to the last three, but expect weaker protection.

**Is a 4-digit lock code secure?**

It keeps an opportunistic handler out, which is what a luggage or cabinet lock is for. Ten thousand combinations is small for anything valuable: someone who can try codes without limit will get through. Use a longer code where the lock allows, keep valuables out of checked luggage, and treat the code as a barrier, not as encryption.

**Does the generator avoid obvious codes like 1234 or 0000?**

No, and deliberately so. Every one of the 10,000 codes is equally likely, so filtering patterns would change the distribution rather than improve it. If you want to avoid a code that someone might try first, generate again until you get one you are comfortable with; the next draw is independent of the last.

**Can I use this for a combination padlock?**

Yes, if the padlock takes four or more digits in a row rather than three rotating dials. Word-based or dial-based combination locks are a different format and need their own word list. This page always returns digits only, with no letters or separators, in the length you select.

## Limitations & Accuracy

The length control accepts 4 to 64 digits, so a three-digit lock is out of scope. Codes are uniform and unfiltered, which means repeats and sequences such as 0000 or 1234 can appear. A four-digit code has only 10,000 combinations and is a convenience barrier, not encryption. The code is generated in the tab and never stored, so it cannot be recovered after you close the page.

## Related Tools

- [Random 4-Digit PIN Code Generator](https://devplain.com/random-4-digit-pin-generator/)
- [Password Generator](https://devplain.com/password-generator/)
- [All tools](https://devplain.com/tools/)

Last updated: 2026-10-30

