Subject: Re: [xsl] exslt random:random-sequence() and Math:random() From: a kusa <akusa8@xxxxxxxxx> Date: Thu, 18 Mar 2010 08:05:18 -0500 |
Yes I was referring to the random:random-sequence function. Thank you for your clarification. I have not been successful in generating unique random sequences using any of the exslt functions. So my next idea was to use the generate-id() function which generates unique ids, and hack it to get a random number. Any thoughts on this approach? On Thu, Mar 18, 2010 at 3:28 AM, Michael Kay <mike@xxxxxxxxxxxx> wrote: > The other question: > >>Does the exslt function generate unique random numbers in a sequential > order? > > They are both exslt functions, I assume you are referring to > random:random-sequence? > > (a) It's defined to return a sequence of numbers, so yes: there is a > sequential order. > > (b) Don't assume the numbers will be unique. If the sequence is truly > random, then occasionally the same number will appear more than once. > > (I remember an exercise in which students were asked to write down a > sequence of 100 digits, chosen randomly. Not only were some digits such as > 3, 7, and 9 much more frequent than others such as 0 and 5, but adjacent > pairs (e.g. a 2 followed by a 2) were almost non-existent, whereas in a > truly random sequence they would occur about once in every ten digits.) > > Regards, > > Michael Kay > http://www.saxonica.com/ > http://twitter.com/michaelhkay > >> -----Original Message----- >> From: Michael Kay [mailto:mike@xxxxxxxxxxxx] >> Sent: 18 March 2010 08:16 >> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx >> Subject: RE: [xsl] exslt random:random-sequence() and Math:random() >> >> >> 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 -> |
---|---|---|
Re: [xsl] exslt random:random-seque, Mike Odling-Smee | Thread | RE: [xsl] exslt random:random-seque, Michael Kay |
RE: [xsl] sorting strings question, Robby Pelssers | Date | RE: [xsl] problem with sending mail, Robby Pelssers |
Month |