We might need to generate random numbers in Excel at times. Random numbers can be used to generate data encryption keys, simulate and describe complicated events, and select random samples from bigger data sets, among other things. In this article, we will demonstrate different ways to make the 4-digit random number generator Excel.
Download Practice Workbook
You can download the workbook and practice with them.
8 Examples of Random 4 Digit Number Generator in Excel
1. Insert RANDBETWEEN Function to Generate 4 Digit Random Number
The RANDBETWEEN function is classified as a Math and Trigonometry function in Excel. The RANDBETWEEN function in Excel generates a random value among two values. Each instance a spreadsheet is accessed or altered, RANDBETWEEN generates a new. Let’s generate 4-digit random numbers using this function. For this, we need to follow the steps down.
STEPS:
- Firstly, select the cell where you want to put the formula using the RANDBETWEEN function. So, we select cell B5.
- Secondly, put the formula into that selected cell.
=RANDBETWEEN(1000,9999)
- Thirdly, press Enter.
- Now, drag the Fill Handle down to duplicate the formula over the range. Or, to AutoFill the range, double-click on the Plus (+) symbol.
- Finally, we are able to see 4 digit random numbers in the cell range B5:B9.
Read More: Excel Formula to Generate Random Number (5 examples)
2. RANDARRARY Function as Random 4 Digit Number Generator in Excel
The RANDARRAY function generates a random number array. The number of rows and columns to fill, the minimum and maximum values, and who should return entire numbers or decimal values are all options. We can use the RANDARRAY function to generate 4-digit random numbers. So, let’s look at the procedures below.
STEPS:
- To begin with, choose the cell where you want to insert the RANDARRAY functions’ formula.
- Second, type the formula below into the selected cell.
=RANDARRAY(5,1,0,9999,TRUE)
- Finally, press the Enter key to finish the procedure.
This will automatically generate 4 digit random numbers into five-row, as we put the number of row 5 into the formula.
Read More: Random 5 Digit Number Generator in Excel (7 Examples)
3. Produce 4 Digit Random Numbers with TRUNC and RAND Functions
The TRUNC function in Excel produces a truncated number with an optional number of digits. The fractional part of the value is removed by TRUNC. The RAND function returns a random specific number that is more than or equal to 0 but less than 1. We can combine the TURNC & RAND functions to generate 4-digit random numbers. Let’s look at the steps to use the combination of those two functions to produce 4-digit random numbers.
STEPS:
- Similarly as previous example, select the cell B5 and substitute the formula
=TRUNC(RAND()*9999,4)
- Then, press Enter. And the formula will show in the formula bar.
- Further, to copy the formula over the range, drag the Fill Handle down or Double-click on the Plus (+) icon.
- And, that’s it! You can see the result in column B.
🔎 How Does the Formula Work?
- RAND()*9999,4: The RAND() will generate a random number between 1 to 9. Multiplying 9999 will increase the number range and the 4 will return only the 4-digit of that random number.
- TRUNC(RAND()*9999,4: This will return the 4-digit of the random number.
Read More: How to Generate Random 10 Digit Number in Excel (6 Methods)
4. Combine ROUND & RAND Functions to Generate 4 Digit Random Number
The ROUND function in Excel produces a number that has been trimmed to a specified number of digits. The RAND function in Excel generates a random value between 0 and 1. We can generate 4 digit random numbers by merging those two functions. So, let’s follow the steps to do that.
STEPS:
- In the same way as before, firstly, select the cell where you want to put the formula to generate random numbers. So, we select cell B5.
- Secondly, enter the below formula into that selected cell.
=ROUND(RAND()*(9999-1000)+1000,0)
- After that, hit the Enter key.
- After that, drag the Fill Handle down to copy the formula over the range. Or, double click on the plus (+) sign. This also duplicates the formula.
- And, this will generate 4-digit random numbers into column B.
🔎 How Does the Formula Work?
- RAND()*(9999-1000)+1000,0: This will mainly multiply RAND() with 9999 to generate only 4-digit random numbers.
- ROUND(RAND()*(9999-1000)+1000,0): This will remove the extra decimal numbers and generate only the 4-digit numbers.
Similar Readings
- Auto Generate Invoice Number in Excel (with 4 Quick Steps)
- How to Generate Random Data in Excel (9 Easy Methods)
- Random Number Generator between Range in Excel (8 Examples)
- How to Generate Random Number with Excel VBA (4 Examples)
- Generate Random Number from List in Excel (4 Ways)
5. Generate 4 Digit Random Number Using LEFT & RANDBETWEEN Functions in Excel
The LEFT function returns the first character or characters in a text string based on the number of characters given. We can combine LEFT and RANDBETWEEN functions to generate 4-digit random numbers. So, let’s follow the procedure.
STEPS:
- As shown in the earlier examples, firstly, select the cell and insert the formula into that cell.
=LEFT(RANDBETWEEN(1,9)&RANDBETWEEN(0,999999999999999)&RANDBETWEEN(0,999999999999999),B5)
- And, press Enter.
🔎 How Does the Formula Work?
- RANDBETWEEN(1,9): This will allow taking a number between 1 to 9.
- RANDBETWEEN(0,999999999999999)&RANDBETWEEN(0,999999999999999),B5: This line of formula will generate random numbers based on the number we put in cell B5.
- LEFT(RANDBETWEEN(1,9)&RANDBETWEEN(0,999999999999999)&RANDBETWEEN(0,999999999999999),B5): This will return the first numbers based on number in the cell B5 is given.
6. Create 4 Digit Random Number by Combining INT & RAND Functions
The INT function in Excel is used to return the closest integer of a given number. When we have a huge number of data sets and each data set is in various formats, such as float, this function returns the integer portion of the number. Let’s follow the steps below.
STEPS:
- Likewise the previous examples, first, select cell B5.
- Then, in that selected cell, type in the formula below.
=INT(RAND()*(9999-1000)+1000)
- Finally, hit the Enter key to complete the process.
- The result will now display in the selected cell, along with the formula in the formula bar.
- Further, drag the Fill Handle down to duplicate the formula across the range. Alternatively, to AutoFill the range, double-click the Plus (+) symbol.
- That’s everything for now! Last but not least, column B shows 4-digit random numbers as a result.
🔎 How Does the Formula Work?
- RAND()*(9999-1000)+1000: This will mainly multiply 9999 with the RAND function to generate 4-digit numbers.
- INT(RAND()*(9999-1000)+1000: This will take the closest integer of the random number and generate only the 4-digit on random numbers.
7. Use Excel Analysis ToolPak to Generate 4 Digit Random Number
There is another way to inject 4-digit random integers that do not require the use of a formula. To generate random data, we can utilize the Analysis ToolPak add-in, but we must first install it. The Analysis ToolPak add-in can be installed in the main procedures. If you are using Microsoft Excel 365, it is installed by default. Now, let’s see the procedure to use this add-in.
STEPS:
- Firstly, select the File tab on the ribbon.
- Secondly, Click Options. Or, use the keyboard shortcut Alt + F + T.
- This will open the Excel Options dialog.
- Then, Click Add-Ins in the pop-up window’s left sidebar.
- After that, select Analysis ToolPak in the Add-ins section.
- Further, select the Excel Add-ins menu at the bottom of the main window from the Manage drop-down bar.
- Next, click the Go button.
- This will open a pop-up window with a list of all accessible Excel Add-ins.
- Checkmark the box Analysis ToolPak and click OK.
- Furthermore, go to the Data tab from the ribbon. There is now an extra category named Analysis on the Excel ribbon’s Data tab, with one button labeled Data Analysis. Click on that.
- This will appear in the Data Analysis dialog box.
- Here, select random Number Generation and click OK.
- Again, a dialog box will appear named Random Number Generation.
- Type the number of columns in the Number of Variables text box and type the number of rows in the Number of Random Numbers text box.
- In the Distribution drop-down menu bar, select Uniform.
- Take the range for a 4-digit number. As we take a range between 1000 and 9999.
- In the Output options, select Output Range. So, we select $B$5:$B$9.
- After that, click on the OK button.
- And, finally we will be able to see the result in the selected range.
Read More: Random Number Generator with Data Analysis Tool and Functions in Excel
8. Excel VBA to Produce 4 Digit Random Number in Excel
We can use Excel VBA to generate random numbers in specific cells. With Excel VBA, users can easily use the code which acts as excel menus from the ribbon. To use the VBA code to generate 4-digit random numbers, let’s follow the procedure.
STEPS:
- In the first place, click the Developer tab on the ribbon.
- Secondly, launch the Visual Basic Editor by clicking on Visual Basic.
- Alternatively, you may access the Visual Basic Editor by pressing Alt + F11.
- Instead of doing this, you can just right-click on your worksheet and go to View Code. This will also take you to Visual Basic Editor.
- This will appear in the Visual Basic Editor where we write our codes to create a table from range.
- And, copy and paste the VBA code shown below.
VBA Code:
Sub FourDigit_RandomNumber()
Dim num As Integer
num = Int((9999 - 100 + 1) * Rnd() + 100)
Range("B5") = num
End Sub
- After that, run the code by clicking on the RubSub button or pressing the keyboard shortcut F5.
- And, finally, following the steps will generate a 4-digit random number in cell B5.
Read More: Excel VBA: Random Number Generator with No Duplicates (4 Examples)
Conclusion
The above examples will show you the Random 4 Digit Number Generator in Excel. Hope this will help you! If you have any questions, suggestions, or feedback please let us know in the comment section. Or you can have a glance at our other articles in the ExcelDemy.com blog!
Related Articles
- How to Generate Random Numbers Without Duplicates in Excel (7 Ways)
- Generate Random Number in Excel with Decimals (3 Methods)
- How to Generate Random Number in a Range with Excel VBA
- Generate Random Number between Two Numbers in Excel (4 Ways)
- Random Number Generator with Normal Distribution in Excel (4 Methods)
- Generate Random Number with Mean and Standard Deviation in Excel