Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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: Generating Double-Digit Random Numbers.

Generating Double-Digit Random Numbers

Written by Allen Wyatt (last updated November 24, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Venkataramanan needs to generate random numbers in the range of -99 to +99, excluding single-digit numbers (-9 to +9). He wonders if there is a way to accomplish the task.

There are a couple of worksheet functions that are often used to generate random numbers in Excel. The RAND function is used to generate a random number between 0 and 1, while the RANDBETWEEN function is used to generate a random number within a range of numbers.

There is no function to do what Venkataramanan wants to do, but you can write a formula that will do the trick. Consider this formula:

=IF(RAND()>0.5,1,-1)*(RANDBETWEEN(10,99))

The first RAND function determines if the result is '+' or '-' and the next RANDBETWEEN function returns the desired number between 10 and 99. When the function is done, you have the desired double-digit random number.

Another formula is similar in nature:

=ROUND(RAND()*89+10,0)*((RAND()<0.5)*2-1)

The first part generates whole numbers in the range of 0 through 89. The formula adds 10 to this, effectively giving a number from 10 to 99. The second part of the formula is then used to randomly determine whether the result should be positive or negative.

Another approach relies entirely on the RANDBETWEEN function and doesn't use any multiplication:

=VALUE(IF(RANDBETWEEN(0,1)=0,"-","")&RANDBETWEEN(1,9)&RANDBETWEEN(0,9))

The formula puts together a string that consists of either a minus sign or a blank followed by two digits. The formula then uses the VALUE function to convert the string to a numeric value. An even shorter version of the formula would be this:

=VALUE(IF(RANDBETWEEN(0,1)=0,"-","")&RANDBETWEEN(10,99))

Another similar formula is the following:

=RANDBETWEEN(10,99)*IF(RANDBETWEEN(0,1),1,-1)

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

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

Understanding Outlining

Outlining, a feature built into Excel, can be a great way to help organize large amounts of data. This tip provides an ...

Discover More

Creating Thin Spaces

Thin spaces are a typographic device that allows you add a bit of space between elements of a document. There are no thin ...

Discover More

Rounding to the Nearest $50

When preparing financial reports, it may make your data easier to understand if you round it to the nearest multiple, ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

How Operators are Evaluated

Operators are used in formulas to instruct Excel what to do to arrive at a result. Not all operators are evaluated in the ...

Discover More

Putting Amounts in Month Columns

Sometimes putting together a formula can be a challenge. Part of the process, though, is examining the data with which ...

Discover More

Displaying a Value and a Percentage in a Single Cell

Sometimes it can be helpful to show both a numeric value and a percentage in the same cell. This can be done through ...

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 nine minus 5?

2019-09-21 08:35:01

Bill Parks

A computer scientist or mathematician would point out that these numbers are really not random, but generated algorithmically. Since it was generated, it can be regenerated with the correct parameters, truly random numbers cannot be. Simple semantics for most people, but an actual distinction i f you are using it to generate crypto information like keys.


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.