Re: [xsl] Random number

Subject: Re: [xsl] Random number
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 24 Sep 2003 06:39:50 -0700 (PDT)
>  I need generate a random number and concatenate with
>  "x" to put like a
>  ID in a node. These numbers have to be always
>  different.
>  <node id="x121334">
>  </node>
>  <node id="x133543">
>  </node>
>  Can somebody help me?

First of all, please note thatthere isn't anything like "a single random

Randomness by definition is aproperty of all numbers in a (potentially
infinite) sequence of numbers.

Therefore, you have to access aservice, which gives you a sequence of
random numbers with the length you desire. This is provided in XSLT by the
FXSL library.


"Casting the Dice with FXSL: Random Number Generation Functions in XSLT"


But you also need them all to be different (unique).

How to do this has been demonstrated a year ago in this list on the topic
of "Randomizing a node-set" -- see e.g.


The idea is that if a sequence of N unique random numbers is wanted, then
we produce a sequence of N random numbers in the range (0, 1] and scale
all of them so that the kth number is scaled in the interval (0, k]. 

So what you need is produced by the template named

And this is part of the file randomList.xsl, contained in FXSL.


Dimitre Novatchev. -- the home of FXSL

P.S. Chances are that what you really need is not random numbers at all --
then just use the generate-id() function/

Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

 XSL-List info and archive:

Current Thread