## Re: [xsl] Seed problem in FXSL randomizeList

 Subject: Re: [xsl] Seed problem in FXSL randomizeList From: Dimitre Novatchev Date: Tue, 6 Oct 2009 06:26:55 -0700
```Jesper,

I am willing to help, but so far you have done little to explain what
you are doing and what is the task being solved. As always, it is very
difficult to help solve a problem, if this problem is not
well-defined.

We shouldn't talk at all about a solution to a problem we don't
understand. And trying to understand the problem from this solution
doesn't help either. Just saying that the solution uses recursion will
not make it clear what the solution actually does. 99.999% of all XSLT
solutions are recursive.

It is quite possible, that once the problem is defined well in such a
way that people understand it, then a simple solution could be found.

Dimitre Novatchev.

On Tue, Oct 6, 2009 at 2:35 AM, Jesper Tverskov <jesper@xxxxxxxxxxx> wrote:
> I have tested the FXSL randomizeList template for a list of type
> items/item. For each item I want the positions of the other item
> elements returned in random order, and I need to make use of the first
> four items in each random order.
>
> The items/item list I have used so far has 140 item elements.
>
> I have managed to solve the above using recursion, Saxon and the
> command line. Processing time is a little less than 10s. The first
> seed is made like this xs:integer(format-time(current-time(),
> '[s][f]')). For the next seed I add 11, etc. It is a mystery to me,
> that if I increase the values of "11" to just "12" the transformation
> seems to go looping. Millions of lines are generated and I have to
> stop the process. (I have tested this strange behavior many times).
>
> Also the random order of the positions returned, are not that random.
> The first third of my lists start with the same position number, the
> next third of the list adds just one to this number, and the last
> third of the list adds two. The rest of the positions look ok, at
> least I have not yet recognized a pattern.
>
> _Here is my question_.
>
> Is there anything I can do to get "random" lists returned, that are
> more "random" for the first position? And how can I change the XSLT
> stylesheet so it will also work for lists of items of at least a
> couple of thousands without the need for experimenting to find a
> number to add to the first seed that will not break the
> transformation?
>
> <xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> B xmlns:f="http://fxsl.sf.net/"; xmlns:xs="http://www.w3.org/2001/XMLSchema";
> B exclude-result-prefixes="f xs">
> B <xsl:import
href="../../../../XSLT/fxsl-xslt2/fxsl-xslt2/f/randomList.xsl"/>
>
> B <!-- Can be applied on any source xml document (ignored) -->
> B <xsl:output omit-xml-declaration="yes" indent="yes"/>
>
> B <xsl:template match="/">
> B <items>
> B  <xsl:call-template name="item"/>
> B </items>
> B </xsl:template>
>
> B <xsl:template name="item">
> B <xsl:param name="pSeed" as="xs:integer"
> select="xs:integer(format-time(current-time(), '[s][f]'))"/>
> B <xsl:param name="num" select="1" as="xs:integer"/>
> B <item>
> B  <name>
> B  B <xsl:value-of select="/items/item[\$num]/name"/>
> B  </name>
> B <xsl:variable name="x">
> B  <xsl:call-template name="randomizeList">
> B  B <xsl:with-param name="pList" select="(1 to count(/items/item))[. !=
\$num]"/>
> B  B <xsl:with-param name="pSeed" select="\$pSeed" as="xs:integer"/>
> B  B  </xsl:call-template>
> B </xsl:variable>
> B  <positions>
> B  <xsl:sequence select="\$x/el[position() &lt; 5]"/>
> B  </positions>
> B </item>
>
> B <xsl:if test="\$num &lt; count(/items/item)">
> B  <xsl:call-template name="item">
> B  B <xsl:with-param name="pSeed" select="\$pSeed + 11" as="xs:integer"/>
> B  B <xsl:with-param name="num" select="\$num + 1" as="xs:integer"/>
> B  </xsl:call-template>
> B </xsl:if>
> B </xsl:template>
> </xsl:stylesheet>
>
> Cheers,
> Jesper
>
>

--
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
-------------------------------------
I enjoy the massacre of ads. This sentence will slaughter ads without
a messy bloodbath.

```