[xsl] Randomness

Subject: [xsl] Randomness
From: Antonio Bueno <atnbueno@xxxxxxxxxx>
Date: Mon, 18 Feb 2002 19:12:43 +0100
Hello everybody.

I've seen there's some interest in generating (pseudo-)random numbers.
For those like me that don't have Java in the server, maybe something
could be done with a simple RNG, like Marsaglia's "Mother-of-All".

I don't know about XPath number formats, if the necessary functions
exist or its efficiency, but here is the info:
[ from http://www.agner.org/random/mother/ ]

Algorithm: S = 2111111111 · Xn-4 + 1492 · Xn-3 + 1776 · Xn-2
           + 5115 · Xn-1 + C

           Xn = S modulo 2^32

           C = floor(S / 2^32)

The last four X'es and C are stored in a buffer as 32-bit unsigned
integers. The intermediate S is a 64-bit unsigned integer.

The X'es and C are initialized to random values based on a seed. They
cannot all be zero.

This algorithm is most effectively implemented in assembly language
where you have an instruction for multiplying two 32-bit integers and
get a 64-bit product. In high level languages you do not have such an
instruction, so you have to use floating point numbers with a mantissa
of at least 63 bits. Not all compilers support this precision, for
example Microsoft Visual C++ does not.

32-bit integer output 
cycle length is 3·10^47
very good randomness 

Anyone dares to make an XSLT/XPath version? :)



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Current Thread