SYNOPSIS<rand $min $max>
<rand $numBytes>
DESCRIPTION
With the first syntax (two arguments), the rand function
returns a pseudo-random integer N, such that $min <= N <
$max. With the second syntax (one argument), rand returns a
string of $numBytes pseudo-random bytes, as a varbyte.
The pseudo-random number generator used is controlled by the
<vxcp randprovider $provider> setting (here),
and defaults to openssl, the OpenSSL provider. The system
provider may also be set, which uses the C rand() or
random() function; this is likely less random than the openssl provider.
The pseudo-random number generator may be seeded via srand
(here), but this is generally not needed, as automatic
seeding will occur on first call of rand or a related function.
DIAGNOSTICS
Given two arguments $min and $max, rand returns a
pseudo-random long N, $min <= N < $max. Given one
argument $numBytes, rand returns $numBytes of
pseudo-random bytes, as a varbyte. Both versions return no
values on error (e.g. OpenSSL library cannot be loaded).
EXAMPLE<rand 0 100>
Your test score is $ret%.
The output might be:
Your test score is 42%.
CAVEATS
The rand function was added Nov. 7 1996.
The one-argument syntax (returning bytes), the openssl provider, and returning zero values on error were added in version 8.01.1773857975 20260318.
Note the differing success return types (long vs varbyte) depending on calling syntax, though both return zero values on error.
The system provider may provide less-random numbers.
SEE ALSOrandpick, srand,
<vxcp randprovider> (here)