Have an idea?

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

Randomizing 2 of 3 select options.


I have a client that wants to randomize a couple response options out of a list of 5. They wish to randomize 1 and 3, but 2,4, and 5 should always stay in their place. Is there an easy way to do this? Moreover, is there a way to do this that doesn't require the additional step of consulting a constructed list column to know which response they chose?

1 - randomized
2 - stays
3 - randomized
4 - stays
5 - stays
asked Nov 17, 2016 by Ron H.

1 Answer

0 votes
Hi Ron,

When a question uses a constructed list, the response stored in the database is the index from the predefined list not the index from the constructed list.  If the respondent selects the item that appears first in the non-randomized list, the response in the data will always store 1 regardless of whether or not that item was randomized for the respondent.  So I believe you can safely use a constructed list for this without having to consult the list column.

This code for the constructed list should do the trick:

ADD(List1, 1)
ADD(List1, 3)
ADD(List1, 2)

"List1" should be replaced with the name of the predefined list.
answered Nov 17, 2016 by Zachary Platinum Sawtooth Software, Inc. (91,500 points)
You could also randomize items 1 & 3 as Zach suggests, and then use the "INSERT" command to stick item 2 into the second position in the list.
Thank you Zachary and Aaron. I think I am missing something here, as I need both 1 and 3 to show in the question, but need 1 and 3 to swap places randomly. If I am reading the list build correctly, I would only get one or the the other, then item 2. Is that correct?
The "ADD(List1)" will make sure that all remaining items are added to the list.
Exactly. As Zach said, the ADD(List1) function takes care of it. When you use ADD and specify the entire list should be added, it will add the list items in the parent list order, but skips any items already on the list. So in Zach's original script, the first two ADD functions specifically add items 1 & 3. When he randomizes on line 3, sometimes it will come out 1,3 and others 3,1. The ListMax on line 4 gets rid of whichever one is second, either leaving a 1 or a 3 on the list. Line 5 adds item 2, so now you either have 1,2 or 3,2 on your list. The final ADD on line 6 just adds whatever is left in order. So, if you have 1,2 in your list, it adds 3,4,5.  If you have 3,2 on your list, then it adds 1,4,5 in order. If you followed my suggestion, you'd use lines 1-3 from Zach's code. Then instead of lines 4 & 5 (ListMax/ADD), you'd say "INSERT(2,List1,2)" to insert into position 2 List 1 item 2. This would shift whatever was in position 2 (either a 1 or a 3) down to position 3. Then you'd ADD(List1) to add items 4,5.
Ah, got it. Thank you both for your help and speedy responses.