Signature (Visual Basic / VBA)
Public Function RandomLongWithinRangeFast( _
ByRef rLower As Long _
, ByRef rUpper As Long _
) As Long
Code Examples
Rnd(-1) = 0.224007
RandomLongWithinRangeFast(1, MaxLong) = 76978304
RandomLongWithinRangeFast(1, MaxLong) = 185440256
RandomLongWithinRangeFast(1, MaxLong) = 352754048
RandomLongWithinRangeFast(1, 100000) = 17974
RandomLongWithinRangeFast(1, 100000) = 57321
RandomLongWithinRangeFast(1, 100000) = 51067
Int(Rnd * (1 + rUpper - rLower) + rLower)
Parameters
| Parameter | Description |
|---|---|
| rLower | The lower limit of the range in which the generated random number will fall. This argument is never modified even though it is passed by-reference. |
| rUpper | The upper limit of the range in which the generated random number will fall. This argument is never modified even though it is passed by-reference. |
Notes & Version History
| Note | The call to the Visual Basic Rnd function in the above example seeds the Visual Basic random number generator so that the sample results can be reproduced. There is generally no need to call the Rnd function within your programs since Entisoft Tools initializes the Visual Basic random number generator once with "Randomize" statement. |
| Note | If rLower > (is greater than) rUpper, this function will produce unexpected results. |
| Note | Some random Long values may not possibly be generated when the range between vLower and vUpper is very large; the RandomLongWithinRange function handles this case better but is slower. |