xsl-list
[Top] [All Lists]

[xsl] How to Do Random "Shuffle"?

2014-09-13 09:29:43
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
for. 

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?

Thanks,

Eliot
—————
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>