RANDOM
The function RANDOM returns a pseudorandom number within a specified range.
This function takes three pieces of input: a minimum Number (which is optional, the default value is 0), a maximum Number (which is optional, the default value is 1), and a boolean (which is optional and can only be used if a minimum and maximum number are entered). It will output a pseudorandom Number between the minimum and maximum numbers. If the boolean value is TRUE, this output will be an integer; if the boolean value is FALSE(the default value), this output will be any Number.
Declaration
Parameters
min (optional, type: Number
) The minimum number in the range from which the pseudorandom number is selected. The default value of this variable is 0. The range the pseudorandom number is selected from is non-inclusive. That is, the output of the RANDOM function will never be exactly the value given for min.
max (optional, type: Number
) The maximum number in the range from which the pseudorandom number is selected. The default value of this variable is 1. The range the pseudorandom number is selected from is non-inclusive. That is, the output of the RANDOM function will never be exactly the value given for max.
require_integer(optional, type: Boolean
) A boolean indicating whether the return value should be an integer or any real number. TRUEmeans that is must be an integer, FALSE means that it can be any real number. This variable is optional and must be used in combination with min and max. The default value is FALSE.
Return Values
random_number (type: Number
) A pseudorandom number between in the range specified.
Examples
The following examples provides a pseudorandom number between 0 and 1, the default values for min and max. Note that the number it outputs is not an integer. Also note that there is not one particular outcome associated with this function. Each time it is called upon, it outputs a different number between 0 and 1.
The following examples provides a pseudorandom number between 0 and 5. Again note that the number it outputs is not an integer, and that there is not one particular outcome associated with this function. Each time it is called on, it provides a different pseudorandom number between 0 and 5:
The following examples provides a pseudorandom number between 5 and 10. Again note that the number it outputs is not an integer, and that there is not one particular outcome associated with this function. Each time it is called on, it provides a different pseudorandom number between 5 and 10:
If only pseudorandom integers are desired as output, the optional variable require_integer must be set to TRUE. (Note that this can only be done if a value is explicitly given for min.) The following example provides a pseudorandom integer between 0 and 10. Note that 0 and 10 do not appear; the numbers specifying the range are excluded:
The optional variable require_integer can also be explicitly set to FALSE, and the function will behave exactly as though the default value was being used. The last example outputs any pseudorandom real number between 5 and 10:
Last updated