Random Number Generator Between Two Numbers

How-to basics · Updated November 23, 2026

To generate a random number between two numbers in Excel, use the formula =RAND()*(b-a)+a for a decimal, or =RANDBETWEEN(a,b) for an integer, where a is the lower bound and b is the upper bound. For example, =RANDBETWEEN(1,100) returns a random whole number from 1 to 100, and =RAND()*(100-1)+1 returns a random decimal between 1 and 100.

How RAND and RANDBETWEEN Work

Excel’s RAND() function generates a random decimal number greater than or equal to 0 and less than 1. It recalculates every time the worksheet recalculates (e.g., when you press F9 or edit any cell). To get a number in a specific range, you scale it: =RAND()*(high-low)+low. For integers, RANDBETWEEN(low, high) returns a whole number inclusive of both endpoints. Both functions are volatile, meaning they change on every recalculation—this is often the first thing users notice and sometimes a source of confusion.

Choosing Between RAND and RANDBETWEEN

  • Use RANDBETWEEN when you need whole numbers, like dice rolls or lottery picks.
  • Use RAND() when you need decimals, such as random times or continuous measurements.
  • For a random decimal with a specific number of digits, combine ROUND with RAND(), e.g., =ROUND(RAND()*10,2) for a number between 0 and 10 with two decimals.

If you need a random date between two dates, convert dates to serial numbers: =RANDBETWEEN(DATE(2025,1,1), DATE(2025,12,31)) and format the cell as a date.

Examples for Common Use Cases

Suppose you want a random number between 5 and 15 (inclusive) as an integer. In cell A1, enter =RANDBETWEEN(5,15). Press Enter. Each recalculation gives a new integer. For a random decimal between 5 and 15, use =RAND()*(15-5)+5. If you need a random percentage between 0% and 100%, use =RAND() and format as percentage. For a random time between 9:00 AM and 5:00 PM, use =RAND()*(TIME(17,0,0)-TIME(9,0,0))+TIME(9,0,0) and format as time.

How to Prevent Random Numbers from Changing

Since both functions recalculate, you may want to freeze the generated values. The simplest way is to copy the cells with the formulas and paste them as values (right-click > Paste Special > Values). Alternatively, you can use a macro to generate a static random number once. For a one-time static random number without a macro, press F9 to recalculate and then immediately copy and paste as values. If you need a list of random numbers that never change, consider using the RANDARRAY function (available in Excel 365 and 2021) to generate an array, then copy and paste as values.

Common Problems and Fixes

  • Numbers change unexpectedly: This is normal. To stop, convert to values.
  • RANDBETWEEN returns #NUM! error: This happens if the lower bound is greater than the upper bound. Check your arguments.
  • RAND() returns a number outside your range: Ensure you used the correct scaling formula. Remember RAND() is always less than 1, so the max is just below your high bound.
  • Duplicates in a list: Random numbers can repeat. If you need unique numbers, generate more than needed and remove duplicates, or use a shuffle method.

Alternatives: RANDARRAY and SEQUENCE

In Excel 365 and 2021, RANDARRAY creates an array of random numbers. For example, =RANDARRAY(5,1,1,10,TRUE) returns 5 rows, 1 column of integers between 1 and 10. The syntax is RANDARRAY(rows, columns, min, max, integer). For a list of unique random integers, combine SORTBY with SEQUENCE: =SORTBY(SEQUENCE(10), RANDARRAY(10)) gives a random permutation of 1 to 10. These functions are not available in older Excel versions.

Using Random Numbers in Google Sheets

Google Sheets has similar functions: RAND() and RANDBETWEEN() work the same way. To generate a random decimal between two numbers, use =RAND()*(b-a)+a. For a static value, copy and paste as values (right-click > Paste special > Values only). Google Sheets also has RANDARRAY but with a different syntax: =RANDARRAY(rows, columns) returns decimals between 0 and 1; to specify range, use =RANDARRAY(rows, columns)* (max-min)+min. For integers, wrap with INT() or use RANDBETWEEN in an array formula with ARRAYFORMULA.

Safety and Accuracy Notes

Random numbers are not truly random—they are pseudo-random, generated by an algorithm. For cryptographic or security purposes, do not use Excel’s RAND or RANDBETWEEN; use a dedicated secure random generator. For simulations, be aware that the sequence may have patterns. Always test your formulas with known bounds to ensure correctness. If you are using random numbers for sampling or statistical analysis, consider setting a seed for reproducibility, which Excel does not natively support—you may need to use a macro or an external tool.

Frequently Asked Questions

How do I generate a random number between 1 and 10 in Excel? Use =RANDBETWEEN(1,10) for an integer, or =RAND()*9+1 for a decimal between 1 and 10 (inclusive of 1, exclusive of 10).

Why does my random number keep changing every time I edit a cell? Because RAND and RANDBETWEEN are volatile functions. They recalculate whenever the worksheet recalculates. To keep a fixed value, copy the cell and paste as values.

Can I generate a random number without a formula? Yes, you can use the Data Analysis Toolpak’s Random Number Generation tool (if enabled) to fill a range with random numbers from various distributions. Or, use a VBA macro: Range("A1").Value = Int((100-1+1)*Rnd+1) for an integer between 1 and 100.

How do I generate a random number that doesn’t include the upper bound? For a decimal, use =RAND()*(b-a)+a which gives a number in [a, b). For an integer exclusive of b, use =RANDBETWEEN(a, b-1).

What is the difference between RAND and RANDBETWEEN? RAND returns a decimal between 0 and 1; RANDBETWEEN returns an integer between two specified numbers. Both are volatile.

Can I generate a random number in a specific range in Google Sheets? Yes, use =RANDBETWEEN(a,b) for integers, or =RAND()*(b-a)+a for decimals. The functions work the same as in Excel.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.