Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Constructed List of Pairs


I have a constructed list in which the 14  items of the original list shall be shown in pairs of 2 that belong to each other.
 I've created separate constructed lists (SP09a-SP09g) for each pairs and tried this:


however, the later insertions destroy my earlier inserted pairs. Is there a way to solve this?
asked Jun 2, 2021 by Kathrin (440 points)
To clarify, you want to randomize the items in their pairs and the pairs in the final list?
Hi there Zachary, I seem to be assuming the same. I'd love to see what you would typically do here. Thanks buddy.
Your solution seems solid here.  Using more lists rather than more unverified Perl is probably preferred for most of our users, but I could create a solution that does all the work in just one constructed list using RNG / Fisher-Yates to handle the randomization.

As I've seen a number of posts like this before, perhaps a generic code would be useful?  I could write a script where the user defines a collection of lists and the code would add the lists in random order - that ought to be fairly easy to use and maybe helpful in more cases, but would just cut out the OrderConList step.  Alternatively, I could write a script where the user defines all their item pairs and the code would do all the work - would only be relevant to this exact problem, but would cut out all the steps besides defining the pairs.
That sounds neat to me. Randomising the paired lists in the same list and excluding the additional OrderConList. Happy to see that when you get a free moment. Thanks again Zachary.
This ought to do it:

Begin Unverified Perl
# Params
my @lists = ('list1', 'list2', 'list3');

# Run
my $i;
for ($i = scalar(@lists); --$i; ) {
    my $j = int(rand($i + 1));
    next if $i == $j;
    @lists[$i, $j] = @lists[$j, $i];

foreach my $list (@lists) {
End Unverified
Much appreciated Zachary. As usual, a nice piece of work!

1 Answer

+1 vote
If I understand correctly, you have a parent list with 14 items, 7 pairs in total. I assume they are defined something like this ...

Pair 1: Items 1-2
Pair 2: Items 3-4
Pair 3: Items 5-6
Pair 4: Items 7-8
Pair 5: Items 9-10
Pair 6: Items 11-12
Pair 7: Items 13-14

You have 7 constructed lists that randomise each pair? Pair 1 would like like this ...

Pair 2 would like like this ...

And so on ...

Now you want to blend the 7 pairs back together but randomise the pairs within this list?

Do I have all of the above correct?

Create a parent list called OrderList with Items 1-7 defined. Label them as a-g.

Now insert this script in to your constructed list that brings all 7 pairs together ...
Begin Unverified Perl

 my $i=1;

 for($i=1; $i<=7; $i++)
End Unverified

This solution should provide randomisation of each pair (via the 7 constructed lists) and then randomise all pairs when brought back together. There are likely to be more efficient solutions, but what I do like about this is the order of the pairs are captured in a constructed list and sometimes I have clients who want to know that slice of information.
answered Jun 2, 2021 by Paul Moon Platinum (98,990 points)
edited Jun 2, 2021 by Paul Moon
Thanks, Paul.  Do you need to randomize OrderList before using it in the final constructed list?
Yes, that would be necessary. Thanks for your quick replies!
Aaahhh yes. Correct Zachary. Thanks for pointing the missing step.

So create OrderConList which uses OrderList as the parent list ...

And I have updated the code in my initial post to change "OrderList" to "OrderConList".