[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: exslt random:random-sequence() and Math:random()
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: 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: 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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|