$random(5)$random - Generate a random number
$random integer
0 <= integer <= 16777215
The $random variable returns a random number in the range 0 - 16777215 (0x0ffffff) on reference to the variable.
The random number generator does not need seeding first as this is handled by MicroEmacs, any attempt to set the variable will result in an error.
The range of the random number generator is fixed across all systems. The value is typically capped to the required range using the &mod(4) arithmetic operator, but note that this creates a slight biasing if 16777216 is not a multiple of the cap (there is a bias towards numbers less than the remainder, but this is generally ignorable).
MicroEmacs uses algorithm xoshiro128++ to generate 32 bit random numbers and then rotated right 8 bits to discard the least significant byte and avoid negative numbers.
This should not be considered a cryptographically secure generator.
In the following example, the returned value is used with the &mod operator to limit the value to a desired range:-
set-variable %random0to9 &mod $random 10
(c) Copyright JASSPA 2025
Last Modified: 2023/10/17
Generated On: 2025/09/29