# Generating Double-Digit Random Numbers

Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Generating Double-Digit Random Numbers.

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 (part of the Analysis ToolPak) 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))
```

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3403) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Generating Double-Digit Random Numbers.

Related Tips:

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

 *Name: Email: Notify me about new comments ONLY FOR THIS TIP Notify me about new comments ANYWHERE ON THIS SITE Hide my email address *Text: *What is 5+3 (To prevent automated submissions and spam.)

Dave    04 Apr 2014, 09:19
The following formula will work, provided:
a) the digits in A1 are greater than the digits in A2
b) both cells have two-digit numbers only.

=LEFT(A1,1)-RIGHT(A2,1) & RIGHT(A1,1)-LEFT(A2,1)

This formula gives you the desired result of 72.

Unexpected results with minus signs are likely unless the conditions are met.
nitish    14 Jul 2013, 04:34
e.g.:- excell cell A1 having value 95
and
cell A2 having value 32
and i want to subtract 9-2 and 5-3 crossly and value i.e.; 72 to be gotted.

# Our Company

Sharon Parq Associates, Inc.

# Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Excel Products

Word Products

# Our Authors

Author Index

Write for Tips.Net