Random
The Random() generates a random number.
This function is NOT SQL compatible. For more information about SQL compatibility, see our documentation.
Returns a random integral number between 0 or a specified minimum value, and a maximum value.
Returns Invalid expression if one of the parameter values is not a valid number, or is a negative number, or when a maximum value is 0, or when the maximum value is less than the specified minimum value or 0 when only the maximum is specified.
As of version 4.2, the Random function also accepts negative numbers when both min and max values are provided - just as long as min < max.
This function uses 32-bit Integers, therefore the range of valid parameters is
-2147483648 and +2147483648
Syntax
Random(max_num)
Random(100)
=> 64
Random()
=> Invalid expression
Random(0)
=> Invalid expression # max_num should be greater than 0
Random(-10)
=> Invalid expression # max_num should be greater than 0
Random(min_num, max_num)
Random(10, 100)
=> 67
Random()
=> Invalid expression
Random(-10, 10)
=> a random value between -10 and 10 (accepted since version 4.2)
Random(20, 10)
=> Invalid expression # max_num should be greater than min_num
Parameters
max_num
numeric
☑️
the maximum value of the generated number.
min_num
numeric
the minimum value of the generated number.
Last updated
Was this helpful?