[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xquery-talk] [xsl] Re: Random number generation : requirements

Subject: Re: [xquery-talk] [xsl] Re: Random number generation : requirements
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 7 May 2014 20:35:50 -0000

On Wed, May 7, 2014 at 12:08 AM, Michael Kay mike@xxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> One of the inherent weaknesses of any pseudo-random number generator
> where the N'th value in the sequence is a function of the (N-1)th value
> is that it can get into loops. For example, if the same value appears twice consecutively
> (which in a truly random sequence will sometimes happen),
> then all subsequent values will be the same.

This is why the argument passed to the number generator needs to be
the index N of the wanted random number (as the Nth number in a
generated random sequence).

In case we have a *lazy*-generated sequence, there is no additional
cost in space and computation.

Also, this is ideal to be done within a fold (or recursion in general)
-- in this case the fold does the book-keeping (like incrementing N)
for you.


Current Thread