<-- Previous || Up || Next -->

Random Integer Within Range Function
Random Values Class

Public Function RandomIntegerWithinRange( _
      Optional ByVal vLower As Variant _
    , Optional ByVal vUpper As Variant _
    ) As Variant

Returns a random Integer number between vLower and vUpper inclusive.
Random numbers will be distributed evenly within the range.

Examples:
    Rnd(-1) = 0.224007
    RandomIntegerWithinRange() = -30418
    RandomIntegerWithinRange() = -27108
    RandomIntegerWithinRange() = -22002
    RandomIntegerWithinRange(1) = 5890
    RandomIntegerWithinRange(1) = 18783
    RandomIntegerWithinRange(1) = 16733
    RandomIntegerWithinRange(1, 100) = 4
    RandomIntegerWithinRange(1, 100) = 41
    RandomIntegerWithinRange(1, 100) = 68
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.
See also:
    RandomIntegerWithinExpRange Function
    RandomLongWithinRange Function
    RandomIntegerWithinRangeVerify Subroutine
vLower: The lower limit of the range in which the generated random number will fall. vLower defaults to MinInteger if it is missing or Null or cannot be fixed up to a number.

vUpper: The upper limit of the range in which the generated random number will fall. vUpper defaults to MaxInteger if it is missing or Null or cannot be fixed up to a number.

Function returns Null if vLower > (is greater than) vUpper.

Function returns vLower if vLower = (equals) vUpper.

Definition:

    CInt(Int(Rnd * (1 + vUpper - vLower) + vLower))

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.