Changes

Jump to navigation Jump to search
1,234 bytes added ,  13:23, 24 May 2018
no edit summary
This [[Module Library|XQuery Module]] contains functions for computing random values. All functions except for [[#random:seeded-double|random:seeded-double]] and [[#random:seeded-integer|random:seeded-integer]] are non-deterministic functions , i. e., they return different values for returning random valueseach call.
=Conventions=
All functions and errors in this module are assigned to the {{Code|<code><nowiki>http://basex.org/modules/random}} </nowiki></code> namespace, which is statically bound to the {{Code|random}} prefix.<br/>All errors are assigned to the {{Code|http://basex.org/errors}} namespace, which is statically bound to the {{Code|bxerr}} prefix.
=Functions=
==random:double==
 {|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|random:double||xs:double}}<br />
|-
| '''Summary'''
|Returns a double value between 0.0 (inclusive) and 1.0 (exclusive).<br />
|-
|
|
|}
==random:integer==
 {|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|random:integer||xs:integer}}<br />{{Func|random:integer|$max as xs:integer|xs:integer}}<br />
|-
|Returns an integer value, either in the whole integer range or between 0 (inclusive) and the given maximum (exclusive)<br />
|-
| '''Errors'''|{{Error|bounds|#Errors}} the maximum value is out of bounds.
|}
==random:seeded-double==
 {|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|random:seeded-double|$seed as xs:integer, $num as xs:integer|xs:double*}}<br />
|-
| '''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 />
|-
|
|
|}
==random:seeded-integer==
 {|width='100%'
|-
| width='90120' | '''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*}}
|-
|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|bounds|#Errors}} the maximum value is out of bounds.<br/>{{Error|negative|#Errors}} the number of values to be returned is negative.
|}
==random:gaussian==
 {|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|random:gaussian|$num as xs:integer|xs:double*}}<br />
|-
| '''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 />
|}
 
==random:seeded-permutation==
 
{| width='100%'
|-
| width='120' | '''Signatures'''
|{{Func|random:seeded-permutation|$seed as xs:integer, $items as item()*|item()*}}
|-
| '''Summary'''|Returns a random permutation of the specified {{Code|$items}}. The random order is created using the initial seed given in {{Code|$seed}}.<br />
|}
==random:uuid==
 {|width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|random:uuid||xs:string}}
|-
| '''Examples'''
|
* {{Code|mathrandom:uuid() eq mathrandom:uuid()}} will (most probably) return the boolean value {{Code|false}}.|} =Errors= {| class="wikitable" width="100%"! width="110"|Code|Description|-|{{Code|bounds}}|The specified maximum value is out of bounds.|-|{{Code|negative}}|The specified number of values to be returned is negative.
|}
=Changelog=
The ;Version 9.0 * Updated: error codes updated; errors now use the module was introduced with namespace ;Version 8.5 * Added: [[#random:seeded-permutation|random:seeded-permutation]] ;Version X8. It includes functionality which was previously located in the 0 * Updated: [[#random:integer|random:integer]], [[Math_Module#random:seeded-integer|Math Modulerandom: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 [[Category:XQueryMath_Module|Math Module]].
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu