# How to Generate Random 4 Digit Numbers in Excel

You can use a two-step process to generate a random 4 digit number in Excel:

Step 1: Use RANDBETWEEN()

```=RANDBETWEEN(0, 9999)
```

This will produce a random integer between 0 and 9,999 (.e.g perhaps the number 468).

Step 2: Use TEXT()

`=TEXT(A1, "0000")`

This will add leading zeros to the number if necessary to ensure that the number has 4 digits (e.g. this would turn 468 into 0468).

The following example shows how to generate a random 4 digit number in Excel in practice.

## Example: How to Generate Random 4 Digit Number in Excel

First, let’s type the following formula into cell A1 to generate a random integer between 0 and 9,999:

`=RANDBETWEEN(0, 9999)`

Next, we can drag this formula down to other cells in column A to generate several random 4 digit numbers:

Notice that each cell in column A contains a random integer between 0 and 9,999.

Also notice that the last cell in the column does not contain 4 digits.

To ensure that each cell in column A has 4 digits, we can type the following formula into cell B1:

`=TEXT(A1, "0000")`

We can then drag and fill this formula down to each remaining cell in column B:

Each cell in column B now contains a random 4 digit number.

Note that if you want to generate a random 4 digit number in a single step you can simply use the following formula:

`=RANDBETWEEN(1000, 9999)`

This will generate a random integer between 1,000 and 9,999.

The only drawback of this approach is that it won’t be possible to have zero as the first digit.