Random Number

RevJeff

Registered User.
Local time
Today, 11:54
Joined
Sep 18, 2002
Messages
129
How can I generate a random number. I need to be able to input two numbers, the low and high ends then generate a random number between those two. I was trying something called "RANDBETWEEN(bottom,top)" that I found in help, but couldn't seem to get it working. Thanks
 
Look up functions RND and RANDOMIZE.

How you do what you wanted is as follows, roughly...

Somewhere in the very early context of the thing that needs to do this, you need to execute a RANDOMIZE statement (this is VBA code...)

The function you describe, however, has to be limited in some ways. If your answer is, for example, required to be an integer or long integer, you have a conversion to perform, because RND only produces SINGLE random numbers (I think it is SINGLE).

Code:
Public Function loRndBetween( loLow as Long, loHigh as Long) as Long

loRndBetween = loLow + CLng( RND * CSng(LoHigh - loLow))

End Function

But this would change if the numbers had to be ordinary integers or currency or some other data type.
 

Users who are viewing this thread

Back
Top Bottom