Subject: RE: [xsl] exslt random:random-sequence() and Math:random() From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Thu, 18 Mar 2010 08:16:08 -0000 |
The math:random() function is defined to return a single random number. This can be problematic, because you presumably want it to return a different random number each time; this means it's not a pure function. But the optimizer doesn't know it's not a pure function, so it might do things like moving the function out of a loop and only calling it once (which means you get the same random number every time). The Saxon-EE optimizer is quite likely to move all the calls on random() into a single global variable. The function random:random-sequence() is designed to get around these problems. Firstly, you can ask it to return a sequence of say 1000 random numbers in a single call. Secondly, you can supply a "seed" - typically a number returned from a previous call on the function, or perhaps just the value of position(). The function thus depends on the value of its arguments, which means it is much less likely to be optimized away. Calling "impure" functions in XSLT is always problematic; the more aggressive your optimizer, the more problematic it becomes. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > -----Original Message----- > From: a kusa [mailto:akusa8@xxxxxxxxx] > Sent: 18 March 2010 00:15 > To: xsl-list > Subject: [xsl] exslt random:random-sequence() and Math:random() > > Hi > > I have a doubt and hoping that the experts can clarify for > me. Aren't the exslt function random:random-sequence() and > Math:random() once and the same? What is the difference if any? > > Does the exslt function generate unique random numbers in a > sequential order? > > Thanks in advance.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] exslt random:random-sequence(, a kusa | Thread | RE: [xsl] exslt random:random-seque, Michael Kay |
Re: [xsl] initial template paramete, G. Ken Holman | Date | RE: [xsl] initial template paramete, Michael Kay |
Month |