是否有可能使用 XQuery 生成随机数? [英] Is there any possibility to generate random numbers using XQuery?
问题描述
我必须使用 XQuery 生成一系列随机数.我找到了一组库,但这些库是付费的.如果有人能给我一个方向,我将不胜感激(最好是代码).
I have to generate a series of random numbers using XQuery.I found a set of libraries but those are paid.If anyone can give me a direction it would be much appreciated(preferably code).
推荐答案
标准 XQuery 语言不提供随机函数,但许多实现提供.一些开源实现示例:
The standard XQuery languages provides no random function, but many implementations do. Some examples for open source implementations:
- BaseX 提供了一个随机模块
- Zorba 也有一个随机模块
- eXist-db 在 Util 模块
- MarkLogic 提供了 xdmp:random() 函数
作为替代方案,XQuery 的大多数 Java 实现(例如 BaseX、Saxon 或 Qizx)提供所谓的Java 绑定以评估 Java 代码:
As an alternative, most Java implementations of XQuery (such as BaseX, Saxon or Qizx) provide so-called Java bindings in order to evaluate Java code:
declare namespace math = 'java:java.lang.Math';
math:random()
如果实现支持最新的 XQuery 3.0 规范,这也可以写成一行:
If the implementation support the latest XQuery 3.0 specification, this can also be written as a one-liner:
Q{java:java.lang.Math}random()
这篇关于是否有可能使用 XQuery 生成随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!