Difference between revisions of "Random Module"

From BaseX Documentation
Jump to navigation Jump to search
m (Text replacement - "<br />" to "<br/>")
Line 12: Line 12:
 
|- valign="top"
 
|- valign="top"
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|random:double||xs:double}}<br/>
+
|<pre>random:double() as xs:double</pre>
 
|- valign="top"
 
|- valign="top"
 
| '''Summary'''
 
| '''Summary'''
Line 23: Line 23:
 
|- valign="top"
 
|- valign="top"
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|random:integer||xs:integer}}<br/>{{Func|random:integer|$max as xs:integer|xs:integer}}<br/>
+
|<pre>random:integer(
 +
  $max as xs:integer := ()
 +
) as xs:integer</pre>
 
|- valign="top"
 
|- valign="top"
 
| '''Summary'''
 
| '''Summary'''
Line 37: Line 39:
 
|- valign="top"
 
|- valign="top"
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|random:seeded-double|$seed as xs:integer, $num as xs:integer|xs:double*}}<br/>
+
|<pre>random:seeded-double(
 +
  $seed as xs:integer
 +
  $num   as xs:integer
 +
) as xs:double*</pre>
 
|- valign="top"
 
|- valign="top"
 
| '''Summary'''
 
| '''Summary'''
Line 48: Line 53:
 
|- valign="top"
 
|- valign="top"
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|random:seeded-integer|$seed as xs:integer, $num as xs:integer|xs:integer*}}<br/>{{Func|random:seeded-integer|$seed as xs:integer, $num as xs:integer, $max as xs:integer|xs:integer*}}
+
|<pre>random:seeded-integer(
 +
  $seed as xs:integer
 +
  $num   as xs:integer
 +
  $max   as xs:integer := ()
 +
) as xs:integer*</pre>
 
|- valign="top"
 
|- valign="top"
 
| '''Summary'''
 
| '''Summary'''
Line 62: Line 71:
 
|- valign="top"
 
|- valign="top"
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|random:gaussian|$num as xs:integer|xs:double*}}<br/>
+
|<pre>random:gaussian(
 +
  $num as xs:integer
 +
) as xs:double*</pre>
 
|- valign="top"
 
|- valign="top"
 
| '''Summary'''
 
| '''Summary'''
Line 73: Line 84:
 
|- valign="top"
 
|- valign="top"
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|random:seeded-permutation|$seed as xs:integer, $items as item()*|item()*}}
+
|<pre>random:seeded-permutation(
 +
  $seed   as xs:integer
 +
  $items as item()*
 +
) as item()*</pre>
 
|- valign="top"
 
|- valign="top"
 
| '''Summary'''
 
| '''Summary'''
Line 84: Line 98:
 
|- valign="top"
 
|- valign="top"
 
| width='120' | '''Signatures'''
 
| width='120' | '''Signatures'''
|{{Func|random:uuid||xs:string}}
+
|<pre>random:uuid() as xs:string</pre>
 
|- valign="top"
 
|- valign="top"
 
| '''Summary'''
 
| '''Summary'''

Revision as of 13:07, 9 March 2023

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.

Conventions

All functions and errors in this module are assigned to the http://basex.org/modules/random namespace, which is statically bound to the random 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

Signatures
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 bounds: 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

Signatures
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 bounds: the maximum value is out of bounds.
negative: 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:seeded-permutation

Signatures
random:seeded-permutation(
  $seed   as xs:integer
  $items  as item()*
) as item()*
Summary Returns a random permutation of the specified $items. The random order is created using the initial seed given in $seed.

random:uuid

Signatures
random:uuid() as xs:string
Summary Creates a random universally unique identifier (UUID), represented as 128-bit value.
Examples
  • random:uuid() eq random:uuid() will (most probably) return the boolean value false.

Errors

Code Description
bounds The specified maximum value is out of bounds.
negative The specified number of values to be returned is negative.

Changelog

Version 9.0
  • Updated: error codes updated; errors now use the module namespace
Version 8.5
Version 8.0

The module was introduced with Version 7.5. It includes some functionality which was previously located in the Math Module.