Returns a random int. The syntax is:
random(max [, seed])
If seed is given then the random number generator is seeded to that value. The random number generator will only be seeded once in each session, and will be randomly seeded on the first call if no seed is supplied. The seed parameter is ignored in the second and later calls to random in a process.
The returned number is always non-negative, and never larger than the limit of the C lib's random number generator (typically either 32767 or 2147483647). If max is non-zero, then the returned number will also be less than max.
This function is typically used to either generate a random number for later use, or to generate a random ordering of result records by adding random to the ORDER BY clause.
Examples of typical use:
SELECT NAME, random(100)
FROM SYSTABLES
The results might be:
NAME random(100) SYSTABLES 90 SYSCOLUMNS 16 SYSINDEX 94 SYSUSERS 96 SYSPERMS 1 SYSTRIG 84 SYSMETAINDEX 96 |
SELECT ENAME
FROM EMPLOYEE
ORDER BY random(0);
The results would be a list of employees in a random order.