Random Function

The Random Function returns a number selected at random within the range indicated by the low and high values.

RAND(low, high)

low
Lowest possible random value.
high
Highest possible random value.
  • Use the Random Function with character or numeric data.
  • If the locale uses a comma as the decimal separator, you must leave a space after the comma.
  • low and high are integers within the range -2,147,483,648 to 2,147,483,647.
  • low and high are further limited by the data type and length for the destination column.
  • low must be less than high.
  • When you use the Random Function in a concatenated expression, a variable length string is returned.

Example

You can use the Random Function to mask or change sales data for a test database. Assume the YTD_SALES column is defined as DECIMAL(7,2). The maximum number of digits preceding the decimal is 5; the possible range for this column is -99999 to 99999. To create test data within a range from 1000 (low) to 89999 (high), specify:

RAND(1000, 89999)

In this example, the function returns random sales values within the range you specified from 1000.00 to 89999.99.