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

Seed problem in FXSL randomizeList

Subject: Seed problem in FXSL randomizeList
From: Jesper Tverskov <jesper@xxxxxxxxxxx>
Date: Tue, 6 Oct 2009 11:35:29 +0200
 Seed problem in FXSL randomizeList
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"
 xmlns:f="http://fxsl.sf.net/" xmlns:xs="http://www.w3.org/2001/XMLSchema"
 exclude-result-prefixes="f xs">
 <xsl:import href="../../../../XSLT/fxsl-xslt2/fxsl-xslt2/f/randomList.xsl"/>

 <!-- Can be applied on any source xml document (ignored) -->
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/">
  <items>
   <xsl:call-template name="item"/>
  </items>
 </xsl:template>

 <xsl:template name="item">
  <xsl:param name="pSeed" as="xs:integer"
select="xs:integer(format-time(current-time(), '[s][f]'))"/>
  <xsl:param name="num" select="1" as="xs:integer"/>
  <item>
   <name>
    <xsl:value-of select="/items/item[$num]/name"/>
   </name>
  <xsl:variable name="x">
   <xsl:call-template name="randomizeList">
    <xsl:with-param name="pList" select="(1 to count(/items/item))[. != $num]"/>
    <xsl:with-param name="pSeed" select="$pSeed" as="xs:integer"/>
     </xsl:call-template>
  </xsl:variable>
   <positions>
   <xsl:sequence select="$x/el[position() &lt; 5]"/>
   </positions>
  </item>

  <xsl:if test="$num &lt; count(/items/item)">
   <xsl:call-template name="item">
    <xsl:with-param name="pSeed" select="$pSeed + 11" as="xs:integer"/>
    <xsl:with-param name="num" select="$num + 1" as="xs:integer"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>

Cheers,
Jesper
http://www.xmlplease.com

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-2011 All Rights Reserved.