Difference between revisions of "Random Module"
Jump to navigation
Jump to search
Line 9: | Line 9: | ||
==random:double== | ==random:double== | ||
+ | |||
{| width='100%' | {| width='100%' | ||
|- | |- | ||
Line 16: | Line 17: | ||
| '''Summary''' | | '''Summary''' | ||
|Returns a double value between 0.0 (inclusive) and 1.0 (exclusive).<br /> | |Returns a double value between 0.0 (inclusive) and 1.0 (exclusive).<br /> | ||
− | |||
− | |||
− | |||
|} | |} | ||
==random:integer== | ==random:integer== | ||
+ | |||
+ | {{Mark|Updated with Version 8.0}}: raise error for invalid input. | ||
+ | |||
{| width='100%' | {| width='100%' | ||
|- | |- | ||
Line 30: | Line 31: | ||
|Returns an integer value, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive)<br /> | |Returns an integer value, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive)<br /> | ||
|- | |- | ||
− | | | + | | '''Errors''' |
− | | | + | |{{Error|BXRA0001|#Errors}} the maximum value is out of bounds. |
|} | |} | ||
==random:seeded-double== | ==random:seeded-double== | ||
+ | |||
{| width='100%' | {| width='100%' | ||
|- | |- | ||
Line 42: | Line 44: | ||
| '''Summary''' | | '''Summary''' | ||
|Returns a sequence with {{Code|$num}} double values between 0.0 (inclusive) and 1.0 (exclusive). The random values are created using the initial seed given in {{Code|$seed}}.<br /> | |Returns a sequence with {{Code|$num}} double values between 0.0 (inclusive) and 1.0 (exclusive). The random values are created using the initial seed given in {{Code|$seed}}.<br /> | ||
− | |||
− | |||
− | |||
|} | |} | ||
==random:seeded-integer== | ==random:seeded-integer== | ||
+ | |||
+ | {{Mark|Updated with Version 8.0}}: raise error for invalid input. | ||
+ | |||
{| width='100%' | {| width='100%' | ||
|- | |- | ||
Line 56: | Line 58: | ||
|Returns a sequence with {{Code|$num}} integer values, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive). The random values are created using the initial seed given in {{Code|$seed}}.<br /> | |Returns a sequence with {{Code|$num}} integer values, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive). The random values are created using the initial seed given in {{Code|$seed}}.<br /> | ||
|- | |- | ||
− | | | + | | '''Errors''' |
− | | | + | |{{Error|BXRA0001|#Errors}} the maximum value is out of bounds.<br/>{Error|BXRA0002|#Errors}} the number of values to be returned is negative. |
|} | |} | ||
==random:gaussian== | ==random:gaussian== | ||
+ | |||
{| width='100%' | {| width='100%' | ||
|- | |- | ||
Line 68: | Line 71: | ||
| '''Summary''' | | '''Summary''' | ||
|Returns a sequence with {{Code|$num}} double values. The random values are Gaussian (i.e. normally) distributed with the mean 0.0. and the derivation 1.0.<br /> | |Returns a sequence with {{Code|$num}} double values. The random values are Gaussian (i.e. normally) distributed with the mean 0.0. and the derivation 1.0.<br /> | ||
− | |||
− | |||
− | |||
|} | |} | ||
==random:uuid== | ==random:uuid== | ||
+ | |||
{| width='100%' | {| width='100%' | ||
|- | |- | ||
Line 85: | Line 86: | ||
| | | | ||
* {{Code|random:uuid() eq random:uuid()}} will (most probably) return the boolean value {{Code|false}}. | * {{Code|random:uuid() eq random:uuid()}} will (most probably) return the boolean value {{Code|false}}. | ||
+ | |} | ||
+ | |||
+ | =Errors= | ||
+ | |||
+ | {| class="wikitable" width="100%" | ||
+ | ! width="110"|Code | ||
+ | |Description | ||
+ | |- | ||
+ | |{{Code|BXRA0001}} | ||
+ | |The specified maximum value is out of bounds. | ||
+ | |- | ||
+ | |{{Code|BXRA0002}} | ||
+ | |The specified number of values to be returned is negative. | ||
|} | |} | ||
=Changelog= | =Changelog= | ||
+ | |||
+ | ;Version 8.0 | ||
+ | |||
+ | * Updated: [[#random:integer|random:integer]], [[#random:seeded-integer|random:seeded-integer]] raise error for invalid input. | ||
The module was introduced with Version 7.5. It includes some functionality which was previously located in the [[Math_Module|Math Module]]. | The module was introduced with Version 7.5. It includes some functionality which was previously located in the [[Math_Module|Math Module]]. | ||
[[Category:XQuery]] | [[Category:XQuery]] |
Revision as of 14:44, 19 August 2014
This XQuery Module contains functions for computing random values. All functions except for random:seeded-double and random:seeded-integer are non-deterministic, i. e., they return different values for each call.
Contents
Conventions
All functions in this module are assigned to the http://basex.org/modules/random
namespace, which is statically bound to the random
prefix.
All errors are assigned to the http://basex.org/errors
namespace, which is statically bound to the bxerr
prefix.
Functions
random:double
Signatures | random:double() as xs:double |
Summary | Returns a double value between 0.0 (inclusive) and 1.0 (exclusive). |
random:integer
Template:Mark: raise error for invalid input.
Signatures | random:integer() as xs:integer random:integer($max as xs:integer) as xs:integer |
Summary | Returns an integer value, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive) |
Errors | BXRA0001 : the maximum value is out of bounds.
|
random:seeded-double
Signatures | random:seeded-double($seed as xs:integer, $num as xs:integer) as xs:double* |
Summary | Returns a sequence with $num double values between 0.0 (inclusive) and 1.0 (exclusive). The random values are created using the initial seed given in $seed . |
random:seeded-integer
Template:Mark: raise error for invalid input.
Signatures | random:seeded-integer($seed as xs:integer, $num as xs:integer) as xs:integer* random:seeded-integer($seed as xs:integer, $num as xs:integer, $max as xs:integer) as xs:integer*
|
Summary | Returns a sequence with $num integer values, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive). The random values are created using the initial seed given in $seed . |
Errors | BXRA0001 : the maximum value is out of bounds.{Error|BXRA0002|#Errors}} the number of values to be returned is negative. |
random:gaussian
Signatures | random:gaussian($num as xs:integer) as xs:double* |
Summary | Returns a sequence with $num double values. The random values are Gaussian (i.e. normally) distributed with the mean 0.0. and the derivation 1.0. |
random:uuid
Signatures | random:uuid() as xs:string
|
Summary | Creates a random universally unique identifier (UUID), represented as 128-bit value. |
Examples |
|
Errors
Code | Description |
---|---|
BXRA0001
|
The specified maximum value is out of bounds. |
BXRA0002
|
The specified number of values to be returned is negative. |
Changelog
- Version 8.0
- Updated: random:integer, random:seeded-integer raise error for invalid input.
The module was introduced with Version 7.5. It includes some functionality which was previously located in the Math Module.