RAND Function [Numeric]

Returns a DOUBLE precision, random number x, where 0 <= x <1, with an optional seed.

Syntax

RAND ( [ integer-expression ] )

Parameters

Parameter

Description

integer-expression

The optional seed used to create a random number. This argument allows you to create repeatable random number sequences.

Returns

DOUBLE

Examples

The following statement returns a 5% sampling of a table:

SELECT AVG(table1.number_of_cars), AVG(table1.number_of_tvs)FROM table1 WHERE RAND(ROWID(table1)) < .05 and table1.income < 50000;

The following statement returns a value of approximately 941392926249216914:

SELECT RAND( 4 ) FROM iq_dummy

Usage

If RAND is called with a FROM clause and an argument in a query containing only tables in IQ stores, the function returns an arbitrary but repeatable value.

When no argument is called, RAND is a non-deterministic function. Successive calls to RAND might return different values. The query optimizer does not cache the results of the RAND function

Note: The values returned by RAND vary depending on whether you use a FROM clause or not and whether the referenced table was created in SYSTEM or in an IQ store.

Standards and Compatibility

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Compatible with Adaptive Server Enterprise.