Random Numbers from Random.org
Wednesday, 3 June 2020 · 3 messages
LS
Leo Studer3 Jun 2020 18:26 #
Hello
I try to use random numbers from random.org.
Here my xpath
let $urand := function(){doc("https://www.random.org/integers/?num=1&min=0&max=1000000000&col=1&base=10&format=html&rnd=new")//*:pre/number() div 1000000000}
return
for $i in 1 to 10 return
$urand()Which brings 10 time the same value, however, every run time a different one. What is wrong with this code?
Thanks in advance for your valuable input
Yours
Leo
OS
Omar Siam3 Jun 2020 18:32 #
In the XQuery data model doc() do not change while a query is evaluated. So a doc() read once can in will be cached for that query. You may get what you want if you use %non-deterministic.
The built in random functions work like that.
Quoted text · Leo Studer · 19 lines
Am 03.06.2020 um 18:26 schrieb Leo Studer: > Hello > > I try to use random numbers from random.org. > > Here my xpath > > let $urand := function(){doc("https://www.random.org/integers/?num=1&min=0&max=1000000000&col=1&base=10&format=html&rnd=new")//*:pre/number() div 1000000000} > > return > for $i in 1 to 10 return > $urand() > > Which brings 10 time the same value, however, every run time a different one. What is wrong with this code? > > Thanks in advance for your valuable input > > Yours > Leo
CG
Christian Grün3 Jun 2020 20:17 #
An additional alternative is to use fetch:xml [1] or (if it’s only about retrieving random numbers) switching to the Random Module [2].
[1] https://docs.basex.org/wiki/Fetch_Module#fetch:xml
[2] https://docs.basex.org/wiki/Random_Module
Quoted text · Omar Siam · 26 lines
On Wed, Jun 3, 2020 at 6:32 PM Omar Siam <Omar.Siam at oeaw.ac.at> wrote: > > In the XQuery data model doc() do not change while a query is evaluated. So a doc() read once can in will be cached for that query. You may get what you want if you use %non-deterministic. > > The built in random functions work like that. > > Am 03.06.2020 um 18:26 schrieb Leo Studer: > > Hello > > I try to use random numbers from random.org. > > Here my xpath > > let $urand := function(){doc("https://www.random.org/integers/?num=1&min=0&max=1000000000&col=1&base=10&format=html&rnd=new")//*:pre/number() div 1000000000} > > return > for $i in 1 to 10 return > $urand() > > Which brings 10 time the same value, however, every run time a different one. What is wrong with this code? > > Thanks in advance for your valuable input > > Yours > Leo
Written for BaseX 9.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery