How to generate random decimal/integer numbers in Excel?
In data analysis, simulation, and testing scenarios, it’s common to need random numbers in Excel—for example, when modeling student scores, financial projections, or generating sample data for presentations. Depending on your requirements, you may need either decimal (fractional) values or whole integers. Excel provides several built-in methods as well as specialized tools and automation techniques for producing both types of random numbers. This tutorial introduces practical methods for generating random decimal or integer numbers in Excel, outlines their applicable situations, and provides some tips and error reminders for smoother operations.
Generating random decimal numbers with formula
Generating random integers using the RANDBETWEEN function
Generating random decimal or integer numbers with Insert Random Data utility![]()
Using VBA macros to automate random decimal/integer generation
Generating random decimal numbers
Generating random decimal numbers between 0 and 1
Excel's RAND function is a simple way to generate random decimal values between 0 and 1, making it ideal for quick simulations or test data creation.
1. Click on any blank cell and enter the following formula:
=RAND() Press Enter, then drag the fill handle across your target range to quickly populate adjacent cells with random decimals. All generated values will fall between 0 and 1.
2. To adjust how many decimal places are displayed, highlight the result range, then click either the Increase Decimal or Decrease Decimal buttons found on the Home tab. This step doesn’t change the underlying random number, but controls its visible precision for easier interpretation.

Generating random decimal numbers between 0 and X
To generate random decimal values within any custom positive range (from 0 up to X), use Excel’s RAND()*X formula. Replace X with the desired maximum value.
1. Select a blank cell and type the formula below (here, 99 is used as an example for X):
=RAND()*99 2. Drag the fill handle from the cell to fill as many cells as needed with random decimals between 0 and 99. This method is suitable for sampling continuous data, such as scores or prices.
3. As before, use the Increase Decimal or Decrease Decimal buttons for custom decimal formatting.
Generating random numbers between X and Y
For scenarios requiring random decimal numbers bounded by two custom limits (X and Y, where X < Y), the following Excel formula is recommended:
=RAND()*(Y-X)+X This generates a number between X and Y. For instance, to get random decimals between 33 and 88:
=RAND()*(88-33)+33 Type the formula in a blank cell, hit Enter, and drag the fill handle to fill multiple cells as needed.
Remember to adjust the displayed decimals for clarity using the Home tab's formatting buttons. After formula entry, you can also copy and paste the results as values if you wish to preserve the random numbers for future analysis without recalculation.
Tip: Every time you recalculate (e.g., press F9, enter a new value, or reopen the workbook), Excel may regenerate random numbers in these cells. To avoid changing values, consider copying and pasting them as values after generation.
Generating random integers using the RANDBETWEEN function
When your application calls for whole numbers—such as simulating lottery draws, assigning randomized IDs, or sampling from integer datasets—Excel's RANDBETWEEN function provides an easy solution. This method is convenient for all users and works for any integer range.
1. In the target cell (for example, A1), enter the following formula to produce a random integer between your chosen lower and upper bounds, X and Y. In this example, we use 10 and 50:
=RANDBETWEEN(10,50) 2. Press Enter to confirm the formula. To generate more random integers, drag the fill handle downward or across adjacent cells.
If you wish to fix the generated results and prevent further changes (since RANDBETWEEN updates with every recalculation), right-click the filled range, choose Copy, then right-click again and select Paste Values. This will lock in your random results.
Precautions: Both boundaries (X and Y) must be integers and Y must be greater than X; otherwise, an error will occur. If you need to generate multiple random integers with no duplicates, consider using advanced tools or formulas, such as Kutools’ Insert Random Data utility.
Generating random decimal or integer numbers with Insert Random Data utility
For frequent or complex random number generation, especially when you want control over uniqueness, format, type (integer, decimal, date, time, string), or need to automate the process, Kutools for Excel’s Insert Random Data utility offers a more versatile solution, eliminating the need for formulas and providing an intuitive dialog box for fast results. It's suited for repetitive tasks, sizable datasets, and when a broader range of randomization is required.
With Insert Random Data, you can perform the following:
Insert random integer numbers
Insert random decimal numbers
Insert random date or time
Insert random string or custom list
After free installing Kutools for Excel, please do as below:
To launch the Insert Random Data tool, click Kutools > Insert > Insert Random Data.
Insert random integer numbers
1. Highlight the cell range where you need random integers.
2. Follow Kutools > Insert > Insert Random Data and choose the Integer tab in the dialog. Here, enter your minimum and maximum integers. If needed, check the Unique values box to prevent duplicate numbers.
3. Click OK; your selected cells are immediately filled with random integer values.
Insert random decimal numbers
1. Select the target cell range for decimal numbers.
2. Open Kutools > Insert > Insert Random Data, switch to the Decimal tab, then specify the decimal bounds and desired precision (number of decimal places). Unique values can be chosen here as well for non-repeating results.
3. Click OK; the random decimal numbers will appear in the selected cells.
Insert random date or time

Insert random string or custom list
Advantages and tips: Kutools’ Insert Random Data utility makes the process much faster, especially for large datasets, removes manual errors, and provides features for dates, times, and custom lists which are not readily available with native Excel formulas.
Note: If you select fewer cells than the number of unique values requested, the operation may fail or result in incomplete data.
Demo: Insert Random Numbers, Dates And Passwords In Excel
Using VBA macros to automate random decimal/integer generation
For advanced users who frequently require large volumes of random numbers or need to automate the process—for example, in repeated simulations, batch testing, or report preparation—VBA macros are a powerful alternative. VBA allows for fine-grained control, including decimal or integer generation in any specified range, along with easy automation and reproducibility. This method is ideal when native formulas or manual tools are too slow or lack specific features.
You can use the following code for random decimal and integer generation:
1. To begin, click Developer Tools > Visual Basic. In the Microsoft Visual Basic for Applications window, choose Insert > Module and paste the following code:
Sub GenerateRandomNumbers()
Dim rng As Range
Dim cell As Range
Dim minVal As Double, maxVal As Double, isInteger As String
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set rng = Application.Selection
Set rng = Application.InputBox("Select destination range", xTitleId, rng.Address, Type:=8)
minVal = Application.InputBox("Enter minimum value", xTitleId, 1, Type:=1)
maxVal = Application.InputBox("Enter maximum value", xTitleId, 100, Type:=1)
isInteger = Application.InputBox("Type 'Y' for integer, 'N' for decimal", xTitleId, "Y", Type:=2)
If minVal >= maxVal Then
MsgBox "Minimum value must be smaller than maximum value.", vbExclamation
Exit Sub
End If
For Each cell In rng
If UCase(isInteger) = "Y" Then
cell.Value = Int((maxVal - minVal + 1) * Rnd + minVal)
Else
cell.Value = Rnd * (maxVal - minVal) + minVal
End If
Next
End Sub 2. To execute, click the
button. A prompt will appear for you to specify the destination range, minimum/maximum values, and choose between integer or decimal output. This macro works for both small and large cell ranges, making it highly suitable for automation and bulk randomization tasks. If any error occurs (for example, min is not less than max), you'll receive a pop-up notification.
Tip: You can assign this macro to a button for one-click operations, or customize the prompts if working with fixed parameters repeatedly.
Note: For decimals, cell formatting can be further adjusted for the desired precision using Excel's formatting tools after generation.
Best Office Productivity Tools
Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time. Click Here to Get The Feature You Need The Most...
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
All Kutools add-ins. One installer
Kutools for Office suite bundles add-ins for Excel, Word, Outlook & PowerPoint plus Office Tab Pro, which is ideal for teams working across Office apps.
- All-in-one suite — Excel, Word, Outlook & PowerPoint add-ins + Office Tab Pro
- One installer, one license — set up in minutes (MSI-ready)
- Works better together — streamlined productivity across Office apps
- 30-day full-featured trial — no registration, no credit card
- Best value — save vs buying individual add-in