#### EXQuery math module

- eXist XML database:
`util:random() xs:double`

`util:random($a as xs:integer) xs:integer`

`math:random() xs:double`

- MarkLogic XML database:
`xdmp:random([$max as xs:unsignedLong])`

`xs:unsignedLong`

as

- Saxon XQuery and XSLT processor:
Returns a somewhat random number between 0 and 1`math:random()`

:Returns a set of random numbers based on an initial seed`random:random-sequence(1,$seed)`

:

`random()`

With six potentially different functions, you begin
to see how difficult it is to write compatible XQuery code when
this much variability exists in extension function libraries to generate a random
number.

`util:random`

`math:random`

The three eXist XML database functions offer perhaps the least-optimal situation,
as the relationship is unclear between and
. I presume that this is concomitant with some refactoring or (common in
open source development) to two functions created by two individuals.
Worst, these two functions might represent some kind of versioning between
old and new.

`util:random`

`xs:integer`

`xs:integer`

`xs:double`

To cap it all, eXist's function adds more diversity
by accepting an seed argument and returning an
(rather than the
that the other two functions return).

`random($max)`

`xs:unsignedLong`

`$max`

MarkLogic defines a single function
that returns a random, unsigned integer between 0 and a number up to 64
bits long. Its return type, being an ,
represents an unsigned integer between 0 and 18446744073709551615
(inclusive). The function optionally defines a maximum value by supplying a
argument of the same type.

`random()`

`random()`

`random()`

Saxon opts to support EXSLT which should be a good thing. However, because EXSLT
currently has no context with
XQuery, using the Saxon functions is somewhat confusing.
The Saxon functions might be the best example of the considerably
confusing situation across XQuery processor implementations of the
function.

This combination of dissimilar and multiple namespaces with different functional signatures makes it impossible to create cross-platform run time XQuery applications, as most XQuery processors will choke during static analysis.

there is a lot of variability in math functions (just take a look at the random() function of eXist, MarkLogic, saxon ... I will review the random based functions. A Math module would be relatively straightforward to define and I think would represent 'low hanging' fruit in kicking off EXQuery.