Main Page » XQuery » Functions » Random Functions

Random Functions

This module contains functions for computing random values. All functions except for random:seeded-double and random:seeded-integer are nondeterministic, 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

Signature
random:double() as xs:double
SummaryReturns a double value between 0.0 (inclusive) and 1.0 (exclusive).

random:integer

Signature
random:integer(
  $max  as xs:integer  := ()
) as xs:integer
SummaryReturns an integer value, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive)
Errors
boundsThe specified maximum value is out of bounds.

random:seeded-double

Signature
random:seeded-double(
  $seed  as xs:integer,
  $num   as xs:integer
) as xs:double*
SummaryReturns 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

Signature
random:seeded-integer(
  $seed  as xs:integer,
  $num   as xs:integer,
  $max   as xs:integer  := ()
) as xs:integer*
SummaryReturns 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
boundsThe specified maximum value is out of bounds.
negativeThe specified number of values to be returned is negative.

random:gaussian

Signature
random:gaussian(
  $num  as xs:integer
) as xs:double*
SummaryReturns 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

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

random:uuid

Signature
random:uuid() as xs:string
SummaryCreates a random universally unique identifier (UUID), represented as 128-bit value.
Examples
random:uuid() eq random:uuid()
Can be expected to return the boolean value false.

Errors

CodeDescription
boundsThe specified maximum value is out of bounds.
negativeThe 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.5Version 8.0Version 7.5
  • Added: New module added. It includes some functionality which was previously located in the Math Functions module.

⚡Generated with XQuery