xsl-list
[Top] [All Lists]

## Re: [xsl] exslt random:random-sequence() and Math:random()

2010-03-18 08:05:42
```Yes I was referring to the random:random-sequence function. Thank you

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(_at_)saxonica(_dot_)com>
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/

```
```-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com]
Sent: 18 March 2010 08:16
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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/

```
```-----Original Message-----
From: a kusa [mailto:akusa8(_at_)gmail(_dot_)com]
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?

```
```--~------------------------------------------------------------------
```
```XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

```
```

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

```
```

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

```
```
--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

```
 Current Thread [xsl] exslt random:random-sequence() and Math:random(), a kusa RE: [xsl] exslt random:random-sequence() and Math:random(), Michael Kay RE: [xsl] exslt random:random-sequence() and Math:random(), Michael Kay Re: [xsl] exslt random:random-sequence() and Math:random(), Mike Odling-Smee Re: [xsl] exslt random:random-sequence() and Math:random(), Martin Honnen RE: [xsl] exslt random:random-sequence() and Math:random(), Michael Kay Re: [xsl] exslt random:random-sequence() and Math:random(), Mike Odling-Smee Re: [xsl] exslt random:random-sequence() and Math:random(), a kusa <= RE: [xsl] exslt random:random-sequence() and Math:random(), Michael Kay Re: [xsl] exslt random:random-sequence() and Math:random(), a kusa RE: [xsl] exslt random:random-sequence() and Math:random(), Michael Kay Re: [xsl] exslt random:random-sequence() and Math:random(), Dimitre Novatchev