[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] How to Do Random "Shuffle"?

Subject: [xsl] How to Do Random "Shuffle"?
From: "Eliot Kimber ekimber@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 13 Sep 2014 14:29:27 -0000

Using XSLT 2 I need to implement rendering of "match table" questions
where you have two sets of items, the match item and the thing it matches
to. I want to present this as a literal table, where the first column is
the match-from items in source order and the second column is the match-to
items, in random order.

I think this is best characterized as a "shuffle" problem, where you want
to reorder a list randomly but all items in the list must be accounted

I can think of a recursive algorithm: given a list, generate a random
integer between 1 and the list length, select that item and add it to the
result list, then call this function on the original list minus the node
you just selected.

Is there an easier or more efficient way to do it?


Eliot Kimber, Owner
Contrext, LLC

Current Thread