random

Returns a random number. The random number generator can be seeded once. 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 if no seed is supplied. The seed is ignored after the first call to random.

If max is not zero, then the random number returned will never be equal to or larger than max or the limit of the random number generator. If max is zero, then the full range of random numbers supported be the system will be returned. The maximum value returned by random(0) is typically either 32767 or 2147483647.

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.


Copyright © Thunderstone Software     Last updated: Jun 9 2017
Copyright © 2017 Thunderstone Software LLC. All rights reserved.