[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: exslt random:random-sequence() and Math:random()

Subject: RE: exslt random:random-sequence() and Math:random()
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 18 Mar 2010 08:28:35 -0000
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.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.