Uniform randomly show from hundreds of possible options | XM Community
Skip to main content
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
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
Hi Nikolay,



Thanks for the thorough and prompt response!



That's really great and I'll go with your design.



As an extra point, do you know if it's possible to display the words in `all_words` uniform randomly (so evenly present the words across the surveys, so no word is shown say 50 times whilst another word is only shown 10 times)?



I'm imagining this may be tricky as it would somehow need to remember the allocation of words between surveys.



Thanks again,

Sam
Hi Sam,



the above algorithm will sort of do that. It's artificial randomisation, obviously but it does work. I've applied the same logic for a project I am working on and I have collected over 250 K datapoints and they are very nicely randomly allocated - negligble deviations; you will never get one word show 50 times and another 10 times. Worst you might get is one word showing 60 times and another 40 or something like that. The more respones the less deviation, obviously.



Good luck!
Great! Thanks again Nikolay

Leave a Reply