Skip to main content
Generator Hut

4 Digit Random Number Generator

Random codes from 0000 to 9999, zero-padded and ready to use as PINs or verification codes.

Generator settings

Between 1 and 10,000.

No number repeats within a batch.

Pads to 4 characters, so 42 becomes 0042.

Generated numbers

Your numbers will appear here. Press Generate to start.

Generate random four digit numbers between 0000 and 9999 for PINs, verification codes, access codes, locker combinations or throwaway test data. Every value comes from your device's cryptographic random source, so results are unpredictable rather than merely shuffled — and because zero-padding is on by default, a draw of 42 arrives as 0042 and stays four characters wide wherever you paste it.

Why use this tool?

PIN ready

Results are zero-padded to a full four characters, so 7 becomes 0007. That is what keypads, banking forms and fixed-width imports expect.

Unique only

Switch on unique mode and no code repeats within a batch — useful when you are issuing one code per person and a collision would be a support ticket.

100% private

Generation happens in your browser using the Web Crypto API. Nothing is sent to a server, nothing is logged, and there is no analytics script watching what you produce.

Bulk generation

Ask for one code or ten thousand. Large batches copy to the clipboard in one click or download as CSV or JSON for a spreadsheet or seed script.

How this 4 digit random number generator works

Each draw asks the browser's Web Crypto API for raw entropy from the operating system's cryptographically secure random number generator — the same source used for TLS session keys. That is a meaningfully different guarantee from JavaScript's Math.random(), which is fast but seeded predictably enough that a determined observer can reproduce its output.

Raw entropy arrives as 32-bit integers, which do not divide evenly into a range of 10,000. Folding them down with a plain modulo would quietly make low numbers more likely than high ones. This tool discards and redraws any value that would land in that uneven tail, so every code from 0000 to 9999 is equally likely.

When unique mode is on, drawn values are tracked and repeats are rejected until the batch is full. Ask for a large slice of the range and the tool switches to a partial Fisher–Yates shuffle instead, which stays fast where naive redrawing would stall.

How to use it

  1. Step 1: Choose how many codes you need

    Enter any number from 1 to 10,000 in the How many field.

  2. Step 2: Set your options

    Turn on Unique only if no code may repeat, keep zero-padding on for true four-character codes, and pick a sort order if you want the batch ordered.

  3. Step 3: Generate, then copy or export

    Press Generate. Select any single code to copy it, or use Copy all, Download CSV or Download JSON for the whole batch.

Example usage

Issuing door codes
Twenty-five unique codes, sorted low to high, pasted straight into the access-control spreadsheet — sorting makes it obvious at a glance that none were duplicated during entry.
Seeding a test database
Ten thousand codes with duplicates allowed, exported as JSON, then loaded as a fixture so your verification flow has realistic data behind it.
Picking a personal PIN
One code, generated and used immediately. A single draw from a uniform distribution avoids the human habit of reaching for a birth year or 1234.

Frequently asked questions

Can I use these numbers as a real PIN?

Yes. Values are drawn from your device's cryptographic random source, so a generated PIN is far stronger than one you invent — human-chosen PINs cluster heavily around dates and repeated digits. Just note that a four digit PIN has only 10,000 possibilities by definition, so it should always be paired with an attempt limit or lockout. It is not a substitute for a password.

Are the numbers really random?

They come from the Web Crypto API, which draws on the operating system's entropy pool rather than a seeded software algorithm. The tool also uses rejection sampling instead of a modulo shortcut, so the distribution is uniform with no bias toward lower numbers.

How do I stop numbers from repeating?

Tick Unique only before generating. Because there are exactly 10,000 four digit combinations, that option can produce at most 10,000 codes in a batch; beyond that a repeat is mathematically unavoidable.

Why do some results start with a zero?

The range 0000 to 9999 includes numbers below 1000, and a four digit code keeps its leading zeros. Zero-padding renders 42 as 0042. If you need plain integers instead, turn padding off and 0042 becomes 42.

Is anything I generate sent to a server?

No. The generator is client-side JavaScript. Your codes exist only in the browser tab until you copy or download them, and closing the tab discards them.

Browse every tool in Random Number Generators & Number Tools.