Re: [xsl] RandomList.xsl from FXSL-xslt2

Subject: Re: [xsl] RandomList.xsl from FXSL-xslt2
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 2 Oct 2009 10:11:02 -0700
On Fri, Oct 2, 2009 at 9:20 AM, Jesper Tverskov
<jesper.tverskov@xxxxxxxxx> wrote:
> Now, in my project I have around 300 items, and I need to pair each
> item with four of the other items randomly, and I will have to do that
> many times a day.
> I only need one seed, but I will have to make 300 transformations
> every time a need to get the items "paired", so XSLT looks like not
> being an option.

It is not necessary at all to "make 300 transformations". Just get a
random sequence in which every of the 300 items is reperesented
exactly once (if I remember well, you'll need the "random-index"
template for this). Then for every item in the sequence get it
together with the four that are its neighbors (for example the item
plus the two preceding and the two following -- with minor exceptions
for items that are at the ends of the sequence).

> So far I have used C# calling a shuffle routine again and again in
> other parts of the project, and I have a feeling that I will have to
> continue doing it that way. Turns out to be one of the few things
> being too nasty in XSLT in my particular use case.

As noted above, even the described C# processing seems to be
needlessly inefficient.

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.

> Cheers,
> Jesper

Current Thread