[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Random number

Subject: Re: Random number
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 24 Sep 2003 06:39:50 -0700 (PDT)
xsl random number
>  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.