This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Randomness


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.

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

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

Saludos,
 Antonio

http://www.webcsd.com
mailto:atnbueno@webcsd.com


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]