Solved
Uniform randomly show from hundreds of possible options
Hi all,
I am running a linguistics experiment where people will be randomly shown words from a list of hundreds of words.
How can I uniform randomly display words to the study's participants? Is there a way to do this using the Qualtrics UI with limited coding needing? (otherwise what options involving coding and/or web service calls are recommended?)
EDIT: Also is there a way to ensure that a different set of words is shown for each question? (E.g. participants are shown 5 words per question and there are 10 questions all with different words)
Thanks for your help,
Sam
Best answer by npetrov937
Add 50 embedded data variables with names from 1 to 50.
Add this javascript code to a random question at the beginning of your survey:
` //function to get n random non-repeating elements from an array
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
}
return result;
}
all_words = [] //type your words here one after another in quotes e.g. ['word1', 'word2', 'word3]
//this is used to generate word1, word2, word3 for testing only - once you've
//populated the above array, get rid of this
for (i=1; i<=100; i++) {
all_words.push('word' + i.toString())
}
//gets 50 random words from the above array
master_list_50words = getRandom(all_words, 50)
//the loop sets the embedded data variables - you need to have 50 embedded data vars with names ranging
//from 1 to 50
for (i=0; i<=master_list_50words.length; i++) {
Qualtrics.SurveyEngine.setEmbeddedData( (i+1).toString(), master_list_50words[i] )
}
this.clickNextButton(); //optional for auto-advancing`
Enter the list of your words in the all_words array (code is nicely commented I think).
Pull your random with Piped Text from embedded data.
Working survey attached.
Hope that helps!
Nikolay
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.
