Changes

Jump to navigation Jump to search
44 bytes added ,  14:53, 31 October 2023
no edit summary
This [[Module Library|XQuery Module]] contains functions for computing random values. All functions except for [[#random:seeded-double{{Function||random:seeded-double]] }} and [[#random:seeded-integer{{Function||random:seeded-integer]] }} are non-deterministicnondeterministic, i. e., they return different values for each call.
=Conventions=
 
{{Mark|Updated with Version 9.0}}:
All functions and errors in this module are assigned to the <code><nowiki>http://basex.org/modules/random</nowiki></code> namespace, which is statically bound to the {{Code|random}} prefix.<br/>
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>random:double||() as xs:double}}<br /pre>|-valign="top"
| '''Summary'''
|Returns a double value between 0.0 (inclusive) and 1.0 (exclusive).<br />
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|random:integer||xs:integer}}<br /pre>{{Func|random:integer|( $max as xs:integer| := ()) as xs:integer}}<br /pre>|-valign="top"
| '''Summary'''
|Returns an integer value, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive)<br />|-valign="top"
| '''Errors'''
|{{Error|bounds|#Errors}} the maximum value is out of bounds.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>random:seeded-double|( $seed as xs:integer, $num as xs:integer|) as xs:double*}}<br /pre>|-valign="top"
| '''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 />
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|random:seeded-integer|$seed as xs:integer, $num as xs:integer|xs:integer*}}<br /pre>{{Func|random:seeded-integer|( $seed as xs:integer, $num as xs:integer, $max as xs:integer| := ()) as xs:integer*}}</pre>|-valign="top"
| '''Summary'''
|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 />|-valign="top"
| '''Errors'''
|{{Error|bounds|#Errors}} the maximum value is out of bounds.<br/>{{Error|negative|#Errors}} the number of values to be returned is negative.
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>random:gaussian|( $num as xs:integer|) as xs:double*}}<br /pre>|-valign="top"
| '''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 />
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>random:seeded-permutation|( $seed as xs:integer, $items as item()*|) as item()*}}</pre>|-valign="top"
| '''Summary'''
|Returns a random permutation of the specified {{Code|$items}}. The random order is created using the initial seed given in {{Code|$seed}}.<br />
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>random:uuid||() as xs:string}}</pre>|-valign="top"
| '''Summary'''
|Creates a random universally unique identifier (UUID), represented as 128-bit value.
|-valign="top"
| '''Examples'''
|
=Errors=
 
{{Mark|Updated with Version 9.0}}:
{| class="wikitable" width="100%"
! width="110"|Code
|Description
|-valign="top"
|{{Code|bounds}}
|The specified maximum value is out of bounds.
|-valign="top"
|{{Code|negative}}
|The specified number of values to be returned is negative.
;Version 8.5
* Added: [[#random:seeded-permutation{{Function||random:seeded-permutation]]}}
;Version 8.0
* Updated: [[#random:integer{{Function||random:integer]]}}, [[#random:seeded-integer{{Function||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]].
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu