Subject: RE: [xsl] Seed problem in FXSL randomizeList From: "Michael Kay" <mike@xxxxxxxxxxxx> Date: Wed, 7 Oct 2009 09:14:34 +0100 |
You seem to be expecting that two pseudo-random sequences starting with different seeds will have no discernable relationship to each other. That might be a property of some randomizers, but it is not necessarily a property of every randomizer, and it appears not to be true of this one. The best you can expect is that within a random sequence, each number is unrelated to the previous one. I would suggest that rather than adding 11 to the seed for your first sequence to get the seed for your second sequence, you use the first ("primary") seed to get a random set of numbers which you then use as "secondary" seeds for the subsequent sequences. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > -----Original Message----- > From: jesper.tverskov@xxxxxxxxx > [mailto:jesper.tverskov@xxxxxxxxx] On Behalf Of Jesper Tverskov > Sent: 06 October 2009 10:35 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] 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() < 5]"/> > </positions> > </item> > > <xsl:if test="$num < 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Seed problem in FXSL rand, Dimitre Novatchev | Thread | Re: [xsl] Seed problem in FXSL rand, Jesper Tverskov |
RE: [xsl] String Case Conversion: T, Michael Kay | Date | Re: [xsl] String Case Conversion: T, Andrew Welch |
Month |