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
number"

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.

See:

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

at:

http://fxsl.sourceforge.net/articles/Random/Casting%20the%20Dice%20with%20FXSL-htm.htm


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.

   http://sources.redhat.com/ml/xsl-list/2002-05/msg00182.html

or

   http://www.topxml.com/code/default.asp?p=3&id=v20020504013704

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
"_randomRecursiveIndex".

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


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- 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
http://sitebuilder.yahoo.com

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


Current Thread