Jim Fuller
jim DOT fuller AT webcomposite DOT com
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:
math:random(): Returns a somewhat random number between 0 and 1
random:random-sequence(1,$seed): Returns a set of random numbers based on an initial 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:randomThe 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:doubleTo 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
$maxMarkLogic 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.