In R-studio, I have generated a numeric distribution (n = 1000) with specific parameters. In my survey, I would like to randomly select a single number from this distribution as part of a decision task for participants. So far, I have created an Embedded Data field in Survey Flow by copy-pasting in my distribution of numbers (separated by comma’s). However, I am unable to use piped text to select a single random number from this distribution to be displayed in my survey text. I would be grateful to receive some advice on how to approach this matter.
Hi
Meanwhile, you can try using ‘Random number’ element present in the survey flow to generate a random number and then pipe text in the survey.
I have come up with a solution to randomly draw from field A1:
<script>
Qualtrics.SurveyEngine.addOnload(function() {
var numberArray = "${e://Field/A1}".split(',');
var randomIndex = Math.floor(Math.random() * numberArray.length);
var selectedNumber = numberArrayrrandomIndex].trim();
Qualtrics.SurveyEngine.setEmbeddedData("SelectedNumber", selectedNumber);
document.querySelector('.QuestionText').innerHTML = "The randomly selected number is: " + selectedNumber;
});
</script>
Thank you
The random number element was not suitable for me because the distribution I would like to draw from has specific characteristics (i.e. not an equal chance for every number in a certain range). I have made a javascript code that I have posted that seems to work. Perhaps it will be useful for someone searching for a similar solution in the future.
Sorry for taking your time and again thanks for your response.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.