Have an idea?

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

How to get the position within a random

Is there a way to use the position within a randomized list in a text?

In a loop there is the function [% LOOPITERATION(Concept) %] that allows to use a number for the concepts per respondent in the order they appear.

In a later Quesiton I would like to use the same number as a reference as: Remember concept 1 from before..

anyl idea how to do that?
asked Jul 5, 2017 by steve
To clarify, if you were to randomize a list from [1, 2, 3] to [2, 3, 1], you want a function where you can put in 3 and get out 2 because the third item appeared in the second position of the randomized list?
yes correct thats the idea
GENIUS - works - thank you

1 Answer

+2 votes
Please try this code out:

[% Begin Unverified Perl
my $listName = 'list2';
my $item = 1;

my $jsArr = LISTVALUESARRAY($listName);
$jsArr =~ s/^.//;
$jsArr =~ s/.$//;
my @arr = split /,/, $jsArr;
my $index = 0;
foreach my $val (@arr) {
    if ($val == $item) {
return $index;
End Unverified %]

Lines 2 and 3 should be updated with the name of the randomized list and the item whose randomized position you want returned.
answered Jul 5, 2017 by Zachary Platinum Sawtooth Software, Inc. (214,575 points)