# question about RAND() function

#### setscrew

##### New Member
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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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

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?

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.

Replies
5
Views
217
Replies
6
Views
253
Replies
4
Views
171
Replies
5
Views
279
Replies
1
Views
105

1,219,807
Messages
6,150,348
Members
450,952
Latest member
Zung

### 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?

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