question about RAND() function

setscrew

New Member
Joined
Sep 24, 2006
Messages
2
when I key in this formula
=30+10*rand()
I should be getting the real number betwwen 30 ~ 40, but somehow, occasionally, I do get something like 28, 29....
Can anyone give an answer to this?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Andrew Fergus

MrExcel MVP
Joined
Sep 9, 2004
Messages
5,432
Hi and welcome to MrExcel!

I wouldn't have thought that was possible but apparently there is a bug with the RAND() function in Excel 2003, see here :
http://office-watch.com/office2003/archtemplate.asp?1-n11

I did a test of 2m random numbers in Excel 2003 and could not reproduce this bug. However, a way to prevent this is to use either of the following :

=30+10*ABS(RAND())

or

=30+10*RANDBETWEEN(0,1)

The 2nd formula requires the 'Analysis Tool Pak' add-in.

HTH, Andrew
 

tusharm

MrExcel MVP
Joined
May 28, 2002
Messages
11,029
You must have the original XL 2003. It's the only version of XL that I know of that had a bug in RAND() that generated negative values. [MS changed the RAND() algorithm in 2003 to improve the quality of the generated random numbers.]

Don't use ABS() to "fix" the problem. There's no guarantee the distribution of the random numbers will be uniform. Instead, update your software with the latest set of patches from the MS site.

Edit: I just noticed Andrew's other recommendation to use RANDBETWEEN. Don't. ATP is considered by many as being worse than RAND when it comes to generating r.v.s.

If you are interested in more on the subject search google as well as the google archives of the XL newsgroups for posts by people like Dave Braden, Jerry Lewis, Martin Brown, and Harlan Grove.

when I key in this formula
=30+10*rand()
I should be getting the real number betwwen 30 ~ 40, but somehow, occasionally, I do get something like 28, 29....
Can anyone give an answer to this?
 

setscrew

New Member
Joined
Sep 24, 2006
Messages
2
Hi Andrew and tusharm,
Thanks for the advise, that really helps!
By the way, will the bug be eliminated by installing office 2003 SP2?
Thanks.
 

Forum statistics

Threads
1,137,198
Messages
5,680,114
Members
419,881
Latest member
Rubber Soul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top