Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Random Numbers in a Range.

Random Numbers in a Range

Written by Allen Wyatt (last updated July 2, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

Excel provides a power function that allows you to easily return a random integer number within a range. For instance, you can use the RANDBETWEEN function to return a random integer number between 50 and 99, or between -25 and 0. The syntax for the function is as follows:

=RANDBETWEEN(lower, upper)

All you need to do is provide the lower and upper values. If the first number you provide is actually higher than the second number, then RANDBETWEEN returns a #NUM! error.

Remember that RANDBETWEEN works only with whole numbers—integers. If you need, instead, to get non-integer values, then you need to use RANDBETWEEN in a bit more complex of a formula. For instance, if you want to have values between 1 and 2, then you could use a formula such as this:

=RANDBETWEEN(100, 200) / 100

This will provide values two two decimal places. If, instead, you wanted values to three decimal places, just make 1000 and 2000 your bounds and divide by 1000.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12364) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Random Numbers in a Range.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Inserting a Non-Breaking Hyphen

Non-breaking hyphens can come in helpful for some types of writing. They force the words (or characters) on both sides of ...

Discover More

Altering the Displayed Format of Numbers to the Nearest 100

Want information in a worksheet to be formatted and displayed as rounded to a power of ten? You may be out of luck, ...

Discover More

Using the SUBTOTAL Function

Need to sum up different ranges of cells? One of the tools you can use is the handy SUBTOTAL function, described in this tip.

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Returning an ANSI Value

Need to know the character value of the first character in a string? It's easy to do, without using a macro, by using the ...

Discover More

Returning the Left-most Characters

When working with text in a formula, you may need to extract the left-most characters from a string of text or from a ...

Discover More

Understanding the LET Function

The LET function provides an easy way to define and use variables within a formula. This tip shows you how you can start ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is six minus 2?

2022-07-02 05:20:44

Andy

The newer RANDARRAY function available in Excel 365 is worth looking at as well. https://support.microsoft.com/en-us/office/randarray-function-21261e55-3bec-4885-86a6-8b0a47fd4d33

As well as the option of random integers within a range, it also allows decimal values and can return an array of random values.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.