8 Ways to Make Random 4 Digit Number Generator in Excel

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.

4 digit random numbers


📁  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.

Example of random 4 digit numbers

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)

RANDBETWEEN function to make 4 digit random numbers generator

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

RANDBETWEEN function result

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

Fill handle to apply RANDBETWEEEN function

📕 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)

RANDARRAY function to make 4 digit random number generator

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

RANDARRAY result

📕 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)

TRUNC & RAND functions to make 4 digit random number generator

🔨 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.

TRUNC & RAND functions result

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

Fill handle to apply TRUNC & RAND function

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)

ROUND & RAND functions to make 4 digit random number generator

🔨 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.

ROUND & RAND functions result

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

Fill handle to apply ROUND & RAND function

📕 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)

LEFT & RANDBETWEEN functions to make 4 digit random number generator

🔨 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.

LEFT & RANDBETWEEN functions result

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

Fill handle to apply LEFT & RANDBETWEEN functions

📕 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)

INT & RAND functions to make 4 digit random number generator

🔨 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.

INT & RAND functions result

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

Fill handle to apply INT & RAND functions

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.

File tab to access Options

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

Selecting Options to access Excel Analysis Toolpak

  • 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.

Adding Excel Analysis Toolpak

  • 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.

Excel Analysis Toolpak to make 4 digit random number generator

  • 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.

Selecting Data Analysis

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

Selecting Random Number Generation

  • 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.

Criteria input for making 4 digit random number generator

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

Decimal Numbers

  • 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.

Formatting Cells to show integers

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

Final result from Excel Analysis Toolpak

📕 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.

Accessing Visual Basic

  • 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.

Inserting 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

Codes to make 4 digit random number generator

  • Finally, press F5 to generate random numbers.

VBA results

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.


Related Article

(Visited 58 times, 1 visits today)
Hassan Shuvo

Hassan Shuvo

Hello, I am Mehedi Hassan Shuvo.I am an Engineering graduate from Bangladesh University of Engineering and Technology. I love reading Thriller books, watching Anime, and playing Cricket. I also love learning about new software. Excel is one of my favorite ones by far. My efforts will be worthwhile if I can utilize my expertise to assist anyone. If you find any faults in my writing please let me know.I will try to correct them as I am learning everyday.

We will be happy to hear your thoughts

Leave a reply

ExcelDen
Logo