Hermann,
Now these values look different for different browsers, and need to
"somehow"
be converted to a seed value for FXSLs random generator.
Ideas?
You could try something simple as the following:
sum(string-to-codepoints($pId)) mod 65536
and see that the results' variety is satisfactory.
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
On Fri, Jul 24, 2009 at 3:28 PM, Hermann
Stamm-Wilbrandt<STAMMW(_at_)de(_dot_)ibm(_dot_)com> wrote:
Dimitre,
If you have decided to go with a service providing random numbers then
xslt-ish way (set based) to do it would be a service receiving a number
and
returning an xml with a specified number of random numbers.
Using a service to provide a random sequence is much more unreliable
and inefficient than just doing this in pure XSLT, as this has been
done by FXSL for many years:
http://fxsl.sourceforge.net/articles/Random/Casting%20the%20Dice%20with%20FXSL-htm.htm
first of all, FXSL is a cool library and the documentation at the link is
informative.
I tried fxsl-1.2 and installed these necessary files on my webserver:
curry.xsl iter.xsl map.xsl random.xsl test-random.xsl
First I realized that it did work on FF3 and not on FF2 (because of the
missing
support of exslt:node-set there). Then I tried it on IE6 and it did not
work first.
After applying below patch it worked under IE6, too.
You may try it out here:
http://www.stamm-wilbrandt.de/en/xsl-list/random/fxsl-1.2/test-random.xml
The output is the same as generated by eg. "xsltproc test-random.xsl
some.xml", but
it is ALWAYS THE SAME output (try it repeatedly).
I knew of the different techniques in generating pseudo random numbers but
what
is really needed is to be able to provide a changing seed (eg. initialize
with
the number of seconds since 1/1/1970, time(NULL) in C).
Then I remembered the generate-id use of Scott, and after reading Michaels
last
post the following fragment seems to be an always changing value:
http://www.stamm-wilbrandt.de/en/xsl-list/random/scott.xml
<xsl:variable name="seed"><a/></xsl:variable>
<xsl:value-of select="generate-id(exsl:node-set($seed))" />
Now these values look different for different browsers, and need to
"somehow"
be converted to a seed value for FXSLs random generator.
Ideas?
=============================================================================
from "http://dpcarlisle.blogspot.com/2007/05/exslt-node-set-function.html"
$ diff random.xsl.orig random.xsl
20c20,21
< exclude-result-prefixes="xsl ext randScale myRandNext
mySingleRandDistFun x"
---
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="xsl ext msxsl randScale myRandNext
mySingleRandDistFun x".
30a32,36
<msxsl:script language="JScript" implements-prefix="ext">
this['node-set'] = function (x) {
return x;
}
</msxsl:script>
$
Mit besten Grüßen / Best wishes,
Hermann Stamm-Wilbrandt
Developer, XML Compiler
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Erich Baier
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
Dimitre Novatchev
<dnovatchev(_at_)gmail
.com> To
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
07/24/2009 11:00 cc
PM
Subject
Re: [xsl] Re: question on random
Please respond to numbers for browser XSLT
xsl-list(_at_)lists(_dot_)mu
lberrytech.com
If you have decided to go with a service providing random numbers then
xslt-ish way (set based) to do it would be a service receiving a number
and
returning an xml with a specified number of random numbers.
Using a service to provide a random sequence is much more unreliable
and inefficient than just doing this in pure XSLT, as this has been
done by FXSL for many years:
http://fxsl.sourceforge.net/articles/Random/Casting%20the%20Dice%20with%20FXSL-htm.htm
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
On Fri, Jul 24, 2009 at 1:48 PM, Vladimir
Nesterovsky<vladimir(_at_)nesterovsky-bros(_dot_)com> wrote:
If you have decided to go with a service providing random numbers then
xslt-ish way (set based) to do it would be a service receiving a number
and
returning an xml with a specified number of random numbers.
--
Vladimir Nesterovsky
http://www.nesterovsky-bros.com/
To Ben:
The cache-append idea was my first thought, but I couldn't think of a
good
way to pull together how to have each request be unique. It's possible
using node-set(), though:
...
...
<xsl:choose>
<xsl:when test="function-available('exsl:node-set')">
<xsl:value-of select="document(concat('/cgi-bin/rand.pl?',
$scale,
'&x=', generate-id(exsl:node-set($seed))))" />
</xsl:when>
<xsl:when test="function-available('msxsl:node-set')">
<xsl:value-of select="document(concat('/cgi-bin/rand.pl?',
$scale,
'&x=', generate-id(msxsl:node-set($seed))))" />
</xsl:when>
...
I tried your solution and after replacing '&x=' with '+' it directly
worked on my local web server!
(I did not know that generate-id works in a browser)
But as already posted it did not work after installed on my real
webserver
because that does not have enough power to handle the six document opens.
Btw, I really like the solution of David Carlisle to provide
exslt:node-set
for IE browsers (and not having to deal with exslt/msxml):
http://dpcarlisle.blogspot.com/2007/05/exslt-node-set-function.html
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--