FWIW,
In actuality, it's the Int() function that causes the formula
[=RAND()*(b-a)+a ] to return an incorrect (upper limit will never be
returned) display.
Using Int(), the formula needs to be adjusted (as you've stated):
=Int(Rand()*(b-a+1)+a)
But, when *not* using Int(), this works accurately:
=Round(Rand()*(b-a)+a,0)
Simply put, the Int() function *truncates* the decimal, no matter how
large, while the Round() function allows the decimal to increment the
value, where appropriate, causing the return to display a value which is
accurately within the limits of the formula.
All I'm stating here is the accuracy of the *display*, not the actual
numerical value within the cell.
--
Regards,
RD
---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
Tyro said:
The solution of =INT(RAND()*(90-21)+21, taken from the Excel help file
from RAND()*(b-a)+a is wrong because RAND()*(b-a)+a never produces b. The
reason for that is the RAND function never produces 1 as a result. The
RAND function is usually described in most documentation as producing a
value between 0 and 1 actually produces a value between 0 and
.999999999999999 as the help file says. Therefore, it can never produce
b. If I want a value between 0 and 2, the formula RAND()*(2-0)+0 will
never produce 2. The maximum it can produce is 2 * .9999999999999999 =
1.99999999999999. So, for you to get random values from 21through 90,
inclusive, the formula needs to be: =INT(RAND(91-21))+21. I didn't
realize the Excel help was wrong until I thought of the .9999999999
limitation on the return value from RAND().
Tyro