In our modern work environment, we may use a variety of passwords, each with a varied length. If you find it difficult to create a password, you may use formulas or a convenient application to do it for you. Not only passwords, among other things, but random numbers can also be used to create data encryption keys, simulate and explain complex occurrences, and choose random samples from larger data sets. In this article, we will show how easy it is to create a random 4-digit number in Excel. So without further ado, letโs make a random 4-digit number generator in Excel.

## ๐ย Download Excel File

Download this file to practice with us.

## Learn to Make Random 4 Digit Number Generator in Excel with These 8 Methods

Today, for the purpose of making a random 4-digit number generator, we will use a couple of functions like **RANDBETWEEN**, **RANDARRAY**, **TRUNC**, **RAND**, **ROUND**, **LEFT**, and **INT**. Some of these functions will act alone, others will have to be incorporated together to make formulas. We will also use the Excel Analysis Toolpak to generate random numbers. Finally, we will create a VBA code to automate the process. So letโs start todayโs lesson.

**Method 1**

### 1. Using RANDBETWEEN Function

Our first function is the **RANDBETWEEN function** to create a 4-digit random number generator. A random integer between two specified numbers is returned by the **RANDBETWEEN** function. Every time you open or modify a worksheet, **RANDBETWEEN** does a new calculation. The function requires two arguments as **Bottom** and **Top**. A random numberโs lower bound is represented by the bottom, while its higher bound is shown by the top. The top and bottom values in the possible range of returned integers are both included in **RANDBETWEEN**. Letโs see how this function generates our 4-digit number.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ**

- Firstly, select cell
**B6**. - Next, we go to the
**Formula bar**where we type the following formula.

**=RANDBETWEEN(1000,9999)**

- Then, when you hit
**Enter**, you will see that the formula generated a 4-digit number.

- Finally, we will use the
**Fill Handle**to generate more for every row.

**๐ Read More: ****Generating Random Number Between Two Numbers in Excel**

**Method 2**

### 2. Applying RANDARRAY Function

The **RANDARRAY function** produces a random number array between two values. The arrayโs size is determined by the rows and columns inputs. The values generated might be decimals or integers. This function takes five optional arguments: **rows**, **columns**, **min**, **max**, and **integer**. Rows, columns, and max are all set to 1 by default, while min is set to 0 and integer is set to **FALSE**. **RANDARRAY** will produce a decimal number between 0 and 1 if no parameters are provided. Letโs see how this function generates our 4-digit number.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ**

- Firstly, select cell
**B6**. - Next, we go to the
**Formula bar**where we type the following formula.

**=RANDARRAY(10,1,1000,9999,TRUE)**

- Finally, when you hit
**Enter**, you will see the formula generated Ten 4-digit numbers.

**๐ Read More: ****4 Ways to Introduce Random Number in Excel with Decimals**

**Method 3**

### 3. Merging TRUNC & RAND Functions

Another way of generating random 4-digit numbers is the combination of the **TRUNC** and **RAND** functions. Based on the number of digits, the **TRUNC** function produces a truncated integer. Like, **TRUNC(8.4)** will return 8. **TRUNC** does not round numbers; it just truncates them as given.ย **TRUNC** accepts two arguments: **number** and **num_digits**. The **number** is the truncated numeric value. The optional **num digits** parameter determines where the number should be truncated. The num digit is set to zero by default (0).

The **RAND** function generates an integer between 0 and 1. Like **=RAND()** will return a value such as 0.584149. When a spreadsheet is accessed or altered, **RAND** dynamically adjusts. The **RAND** function does not accept any parameters. Letโs use these functions to generate our 4-digit numbers.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ**

- Firstly, select cell
**B6**. - Next, we go to the
**Formula bar**where we type the following formula.

**=TRUNC(RAND()*9999)**

**๐จ Formula Breakdown **

๐ A number between 1 and 9 will be generated by the **RAND()** function. By multiplying 9999, the number range will be expanded, and we will get decimal numbers.

๐ Then the **TRUNC** function will truncate the generated number and eliminate the decimals.

- Then, when you hit
**Enter**, you will see the formula generated a 4-digit number.

- Last but not least, use the
**Fill Handle**to generate more for every row.

Thus, you will get random 4-digit integers.

**๐ Read More: ****5 Ways to Generate Random Number Between 0 and 1 in Excel**

**Method 4**

### 4. Combining ROUND & RAND Functions

The next method we will discuss is the combination of the **ROUND** and **RAND** functions. The **ROUND** function gives an integer with a specified number of rounded digits. The right or left of the decimal point can be rounded using the **ROUND** function. There are 2 arguments for the** ROUND** function: number and num_digits. As specified above, the **RAND** function generates an integer between 0 and 1. Letโs use these functions to generate our 4-digit numbers.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ**

- Firstly, Select Cell
**B6**. - Next, we go to the
**Formula bar**where we type the following formula.

**=ROUND(RAND()*(9999-1000)+1000,0)**

**๐จ Formula Breakdown **

๐ A number between 1 and 9 will be generated by the **RAND()** function. By multiplying (9999-1000)+1000, the number range will be expanded, and we will get decimal numbers.

๐ Then the **ROUND** function will eliminate the decimals.

- Then, when you hit
**Enter**, you will see the formula generated a 4-digit number.

- Finally, we will use the
**Fill Handle**to generate more for every row.

**๐ Read More: ****6 Ways to Generate Random 10-Digit Number in Excel**

**Method 5**

### 5. Applying LEFT & RANDBETWEEN Functions Together

The **LEFT** function removes a predetermined amount of characters from a text stringโs left side. **LEFT(โRomanโ,2)**, for instance, returns โRoโ. The second option, **num_chars**, specifies how many characters should be extracted. If no value is specified for num chars, it defaults to 1. If num chars exceed the amount of allowed characters, **LEFT** returns the original text string. We will incorporate **LEFT** and **RANDBETWEEN** functions to create a 4-digit random number generator in Excel.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ**

- Firstly, select cell
**B6**. - Next, we go to the
**Formula bar**where we type the following formula.

**=LEFT(RANDBETWEEN(1,9)&RANDBETWEEN(0,999999999)&RANDBETWEEN(0,999999999),4)**

**๐จ Formula Breakdown **

`๐`

A number between 1 and 9 will be generated by the **RANDBETWEEN(1,9)** function.

`๐`

**RANDBETWEEN(0,999999999)&RANDBETWEEN(0,999999999)** will create random numbers between 0 and 99999999.

`๐`

Then the **LEFT** function will take the generated number and only preserve the first 4 and eliminate the rest.

- Then, when you hit
**Enter**, you will see the formula generated a 4-digit number.

- Finally, we will use the
**Fill Handle**to generate more for every row.

**๐ Read More: ****7 Ways to Create Random 5 Digit Number Generator in Excel**

**Method 6**

### 6. Incorporating INT & RAND Functions

By rounding to the nearest integer, the **INT function** provides the numeric portion of a decimal number. **INT(50.7)**, for instance, returns 50, whereas **INT(-20.2)**, returns -21. We can use the **INT** function to round up an integer provided by the **RAND** function to create a 4-digit random number.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ**

- Firstly, select cell
**B6**. - Next, we go to the
**Formula bar**where we type the following formula.

**=INT(RAND()*(9999-1000)+1000)**

**๐จ Formula Breakdown **

๐ A number between 1 and 9 will be generated by the **RAND()** function. By multiplying (9999-1000)+1000, the number range will be expanded, and we will get decimal numbers.

๐ Then the **INT** function will eliminate the decimals.

- Then, when you hit
**Enter**, you will see the formula generated a 4-digit number.

- Finally, we will use the
**Fill Handle**to generate more for every row.

**Method 7**

### 7. Using Data Analysis Toolpak

We may perform data analysis and numerous other crucial computations using the Excel add-in known as the **Data Analysis ToolPak**. This function offers tools for the analysis of financial, statistical, and engineering data. This add-in is disabled in Excel by default.ย You will have access to a number of statistical tools, such as histograms, correlation, a variety of z-test and t-test functions, and random number generators, thanks to the integrated **Data Analysis ToolPak**. So letโs first enable the toolpak and then generate random 4-digit numbers.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ **

- Firstly, Go to
**File**Tab, click on it and Excel will show its Backstage view.

- Here, at the left-down corner, you will see
**Options**.

- After you click
**Options**, a box containing several options will appear. - Then, on the
**Excel Options**left sidebar, click**Add-Ins**. - Here, under the
**Add-ins**area, pick**Analysis ToolPak**. Then, select the**Excel Add-ins**menu from the**Manage**drop-down bar at the bottom. Then, press**Go**.

- This will display a list of all available
**Excel Add-ins**in a dialogue box. Next, check the box for**Analysis ToolPak**and then click**OK**.

- Now, go back to the ribbon and in the
**Data**tab, you will see another group**Analysis**at the end of the ribbon. Here, click**Data Analysis**.

- Hence, selecting
**Data analysis**will open a window. Click**Random Number Generation**and subsequently**OK**.

- The
**Random Number Generation**window will once again show up. - In the text boxes labeled
**Number of Variables**and**Number of Random Numbers**respectively, input the number of columns and rows. We have 1 column and 10 rows so we have entered 1 and 10 respectively. - Next, choose
**Uniform**in the Distribution box. - Since we want 4-digit random numbers, weโre using a range of 1000 to 9999.
- Lastly, for our final input, we need to specify the location of our output result. We thus choose cell
**$B$6:$B$15**. Once youโve finished, press**OK**.

- Then, when you hit
**OK**, you will see that the generated 4-digit numbers are not integers.

- So We press
**Ctrl+1**to access**Format Cells**to show integer numbers. From**Number**tab, under**Catagory**box, select**Number**. You will find a box that will let you choose the number of the decimal place you want. We will select 0. Finally, press**OK**.

Thus, you have some random 4-digit numbers on your table.

**๐ Read More: ****8 Easy Tricks to Generate Random Data in Excel**

**Method 8**

### 8. Implementing VBA Code

Finally, we have come to our last method, where we will be using the VBA script to to Make Random 4 Digit Number Generator in Excel. To write VBA code, we need to enable the **Developer **tab in our Ribbon. Find here how to **access the Developer tab**.

After you enable the Developer tab, follow these steps to write your code.

**โฌ๏ธโฌ๏ธ STEPS โฌ๏ธโฌ๏ธ**

- Firstly, select the
**Developer**tab and click**Visual Basic**at the left corner of the ribbon.

- Subsequently, a window (Microsoft Visual Basic for Applications) will open, in which we will enter our code to calculate age all at once. Go to
**Insert**and click**Module.**

- Next, a white module will show up to write your code. I have already included the code so that you may copy and paste it into your module.

```
Sub RandomNumberGenerator()
Range("B6:B15") = WorksheetFunction.RandArray(10, 1, 1000, 9999, True)
End Sub
```

- Finally, press
**F5**to generate random numbers.

You will see all of your results in the Excel workbook.

## ๐ Important Notes

`๐`

If any formula generates decimal numbers, you have the option to show only the integer number by formatting cells. Press **Ctrl+1** to access **Format Cells**.

`๐`

In the VBA code, you can use any formula described above.

`๐`

Every time you refresh or press **Enter**, the formulas will generate new random numbers.

## ๐ Takeaways from This Article

`๐๏ธ`

Firstly, we used **RANDBETWEEN** function to make a 4-digit number generator in Excel.

`๐๏ธ`

Then, we used the **RANDARRAY** function to do the same.

`๐๏ธ`

Next, we merged the **TRUNC** and **RAND** functions to make a random 4-digit number generator in Excel.

`๐๏ธ`

Again, we used **ROUND** and **RAND** functions together to provide integer 4-digit numbers. We also used a similar formula exchanging **INT** function for **ROUND**.

`๐๏ธ`

As far as functions go, we combined **LEFT** and **RANDBETWEEN** to choose only the left 4-digit numbers.

`๐๏ธ`

We also used the **Excel Analysis Toolpak** which is an add-in, to generate random numbers.

`๐๏ธ`

Finally, we created a **VBA** code to automate the entire process.

## Conclusion

We have come to the conclusion of our article. I hope you will be able to use these functions and formulas to make a 4-digit random number generator in Excel. If you have any questions, feel free to comment below. I will try to answer them as soon as possible. Have fun using Excel, and you can visit **Excelden.com** for more tutorials. Thank You.