Generate Random Numbers in Excel
- Randomness has many uses in science, art, statistics, cryptography, gaming, gambling, and other fields.Generating Random numbers in excel is important because many things in real life are so complicated that they appear random. Therefore, to simulate those processes, we need random numbers.
Many randomizing devices such as dice, shuffling playing cards, and roulette wheels have been developed for use in games of chance. However, these cannot be used for digitized files. That is why we need tools for generating random numbers in Excel.
You are free to use this image on you website, templates, etc., Please provide us with an attribution linkHow to Provide Attribution?Article Link to be HyperlinkedFor eg:Source: Random Numbers in Excel (wallstreetmojo.com)
How to Generate Random Numbers in Excel?
There are several methods to generate a random number in Excel. We will discuss the two of them: RAND() and RANDBETWEEN() functions.
#1 – RAND() Function
To generate a random number in Excel between 0 and 1(excluding), we have a RAND() function in Excel.
RAND() functionsRAND() FunctionsThe RAND function in Excel, also known as the random function, generates a random value greater than 0 but less than 1, with an even distribution among those numbers when used on multiple cells. read more return a random decimal number that is equal to or greater than 0 but less than 1 (0 ≤ random number <1). In addition, the RAND function recalculates when a worksheet is opened or changed (volatile function).
The RAND function returns the value between 0 and 1 (excluding).
We must type “=RAND()” in the cell and press the “Enter.” The value will change whenever any change is made in the sheet.
How to Generate Random Numbers in Excel for more than One Cell?
If we want to generate random numbers in Excel for more than one cell, then we need:
- First, select the required range, type =”RAND(), “and press the “Ctrl+Enter” to give us the values.
How to Stop Recalculation of Random Numbers in Excel?
As the RAND function recalculates, if any change in the sheet is made, we must copy and then paste the formulas as values if we do not want values to be changed every time. For this, we need to paste the values of the RAND() function using Paste Special so that it would no longer be a result of the “RAND ()” function. It will not be recalculated.
To do this,
We need to make the selection of the values.
Press the “Ctrl+C” keys to copy the values.
Without changing the selection, press the Alt+Ctrl+V keys to open the “Paste Special” dialog box.
Choose “Values” from the options and click on “OK.”
We can see that the value in the formula bar is the value itself, not the RAND() function. Now, these are only values.
There is one more way to get the value, only not the function as a result, but that is only for one cell. If we want the value the very first time, not the function, then the steps are:
- First, type =RAND() in the formula bar, press F9, and press the “Enter” key.
After pressing F9, we get the value only.
Value from a Different Range other than 0 and 1 using RAND()
As the RAND function returns a random decimal number between 0 and 1 only, if we want the value from a different range, then we can use the following function:
Let ‘a’ be the start point.
And ‘b’ be the end point
The function would be ‘RAND()*(b-a)+a’
For example, if we have 7 as “a” and 10 as “b,” then the formula would be “=RAND()*(10-7)+7.”
RANDBETWEEN() Function
As the function’s name indicates, this function returns a random integer between given integers. Like the RAND() function, this function also recalculates when a workbook is changed or opened (volatile function).
The formula of the RANDBETWEEN Function is:
Bottom: An integer representing the lower value of the range.
Top: An integer representing the lower value of the range.
To generate random numbers in Excel for the students between 0 and 100, we will use the ‘RANDBETWEEN’ function.
First, we must select the data, type the formula, =RANDBETWEEN(0,100), and press the “Ctrl + Enter” keys. You can prefer the below-given screenshot.
As values will recalculate, we can only use “Alt+Ctrl+V” to open the “Paste Special” dialog box to paste as values.
Follow the steps given below in the screenshot.
Like the RAND() function, we can also type the RANDBETWEEN function in the formula bar, pressing F9 to convert the result into value, and then press the “Enter” key.
Things to Remember
- If the bottom is greater than the top, the RANDBETWEEN function will return #NUM! Error.If either of the supplied arguments is non-numeric, the function will return #VALUE! Error.Both RAND() and RANDBETWEEN() functions are volatile functions (recalculates). Hence, it increases the processing time and can slow down the workbook.
Random Numbers in Excel – Project 1
We can use the RANDBETWEEN() function for getting random dates between two dates.
We will be using two dates as the bottom and top arguments.
After making the selection, we need to copy down the formula using the shortcut (Ctrl+D).
We can change the start date (D1) and end date (E1) to change the top and bottom values for the function.
Random Numbers in Excel – Project 2 – Head and Tail
To randomly choose head and tail, we can use the CHOOSE function in excel with the RANDBETWEEN function.
We need to copy the formula into the next and next cell every time in the game, and “Head” and “Tail” will come randomly.
Random Numbers in Excel – Project 3 – Region Allocation
Many times, we have to imagine and create data for various examples. For example, suppose we have data for sales, and we need to allocate three different regions to every sale transaction.
Then, we can use the RANDBETWEEN function with the CHOOSE function.
We can drag the same for the remaining cells.
Random Numbers in Excel – Project 4 – Creating Ludo Dice
Using the RANDBETWEEN functionUsing The RANDBETWEEN FunctionRANDBETWEEN excel formula determine random numbers between two extreme variables (bottom and top numbers). The user needs to fill in the bottom and top numbers in the syntax =RANDBETWEEN (bottom, top) to acquire the random integer.read more, we can also create dice for Ludo. We need to use the RANDBETWEEN function in Excel VBA for the same. Please follow the below steps:
Merge the four cells (B2:C3) using Home Tab-> Alignment Group-> Merge & Center.
Apply the border to the merged cell using the shortcut key (ALT+H+B+T) by pressing one key after another.
Center and middle align the value using Home Tab-> Alignment Group -> “Center” and “Middle Align” commands.
To create the button, use DeveloperDeveloperEnabling the developer tab in excel can help the user perform various functions for VBA, Macros and Add-ins like importing and exporting XML, designing forms, etc. This tab is disabled by default on excel; thus, the user needs to enable it first from the options menu.read more tab -> Controls Group -> Insert -> ‘Command Button’
Create the button and choose “View Code” from the “Controls” group on “Developer.”
After choosing “CommandButton1” from the dropdown, paste the following code:
RN = (“=RANDBETWEEN(1,6)”)
Cells(2, 2) = RN
Please save the file using the .xlsm extension as we have used the VBA code in the workbook. After coming to the Excel window, deactivate the “Design Mode.“
Now, whenever we click the button, we get a random value between 1 and 6.
Recommended Articles
This article is a guide to Random Numbers in Excel. Here, we discuss generating random numbers in Excel using the RAND() and RANDBETWEEN functions along with multiple projects and downloadable Excel templates. You may also look at these useful functions in Excel: –
- Randomize List in ExcelRandomize List In ExcelRandomizing a list in excel means selecting a random value from the data, to randomize a whole list in excel. There are two excel formulae for this: the =RAND() function, which returns any random value to the cell and then allows us to sort the list, and the =RANDBETWEEN() function, which returns random values to the cell from a number range specified by the user.read moreAuto Number in ExcelAuto Number In ExcelThere are two approaches for auto numbering. To begin, fill the first two cells with the series you wish to insert and drag it to the table’s end. Second, use the =ROW() formula to get the number, and then drag it to the table’s end.read moreVBA Random NumberVBA Random NumberTo generate random numbers in vba we have an inbuilt function called RND. It just takes two numbers as input to generate random between these numbers. It creates random numbers which are greater than 0 and smaller than 1.read moreRAND Function in ExcelRAND Function In ExcelThe RAND function in Excel, also known as the random function, generates a random value greater than 0 but less than 1, with an even distribution among those numbers when used on multiple cells. read more