This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dev:sql:functions:random [2009/12/07 14:46] tdo created |
dev:sql:functions:random [2010/07/09 20:26] els |
||
---|---|---|---|
Line 1: | Line 1: | ||
{{page>:top_add&nofooter&noeditbtn}} | {{page>:top_add&nofooter&noeditbtn}} | ||
- | <html><div align="center"><span style="color:red">DRAFT</span></div></html> | ||
- | ====== Omnidex SQL Function: $RANDOM ====== | ||
{{page>:sql_bar&nofooter&noeditbtn}} | {{page>:sql_bar&nofooter&noeditbtn}} | ||
+ | ====== Omnidex SQL Function: $RANDOM ====== | ||
===== Description ===== | ===== Description ===== | ||
- | Returns a pseudo-random number. The term "pseudo-random" is used as randomization is done using the Posix rand and srand functions. While these routines do provide satisfactory randomization for most applications, the numbers generated are not entirely random. | + | Returns a pseudo-random number. The term "pseudo-random" is used since randomization is done using the POSIX rand and srand functions. While these routines do provide satisfactory randomization for most applications, the numbers generated are not entirely random. |
+ | |||
+ | If seed is specified, it is used to start the random number generator. Note that only a single $random stream can be used in the process. If there are multiple $random functions in a select, only the first seed is used. Seed must be a literal. | ||
+ | |||
+ | This function returns an INTEGER datatype. | ||
- | If seed is specified, it is used to start the random number generator. Note that only a single $random stream can be used in the process. If there are multiple $random functions in a select, only the first seed is used. Seed must be a literal. The return value is INTEGER length 4. | ||
===== Syntax ===== | ===== Syntax ===== | ||
- | $RANDOM[(seed)] | ||
- | == (seed) == | + | $RANDOM( numeric_expression [, seed] ) |
- | Optional. Seed must be a literal. | + | == numeric_expression == |
+ | |||
+ | Required. Any expression that returns a numeric expression. | ||
+ | == seed == | ||
+ | Optional. A literal integer //n// is an integer indicating the number of digits to the right of the decimal. The default is 0. | ||
+ | |||
===== Example ===== | ===== Example ===== | ||
- | ==== Example 1 ==== | + | ==== Example 1: $RANDOM without a seed ==== |
- | $RANDOM(9) | + | |
- | 68 | + | <code> |
- | 6151 | + | |
- | ... | + | > select $random rnd from $omnidex; |
+ | |||
+ | RND | ||
+ | ----------- | ||
+ | 1210253353 | ||
+ | </code> | ||
+ | |||
+ | ==== Example 2: $RANDOM with a seed ==== | ||
+ | |||
+ | <code> | ||
+ | > select $random(12345) rnd from $omnidex; | ||
+ | |||
+ | RND | ||
+ | ----------- | ||
+ | 1255939488 | ||
+ | </code> | ||
+ | |||
+ | ====== Additional Resources ====== | ||
+ | |||
+ | See also: | ||
+ | {{page>dev:sql:functions:see_also_math&noheader&nofooter&noeditbtn}} | ||
{{page>:bottom_add&nofooter&noeditbtn}} | {{page>:bottom_add&nofooter&noeditbtn}} | ||
+ |