I am struggling with an issue and I am wondering whether anybody has a good idea how to solve it.
I want to ask my respondents a question after showing them a brief text. It is a survey experiment so not all respondents receive the same information. A randnumber will decide what text they get to see.
Later in the survey, they will receive the same question again, but I want to make sure that they do not get the same information they have received before the first question.
Do you know whether there is a way to "exclude" numbers from a randnumber once they have been used before to make sure that they are not repeated?
I don't know of a way to do it with Expression Manager but here is a JavaScript solution.
Create multiple-short-text question with two sub-questions.
Add this script to the source of that question. Adjust the "minNumber" and "maxNumber" variables as necessary. The script will create an array of possible numbers, randomize it and then load the first two numbers into the sub-questions. You can then base relevance on those sub-questions.
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){// Identify this questionvar thisQuestion = $('#question{QID}');var input1 = $('input:text:eq(0)', thisQuestion);var input2 = $('input:text:eq(1)', thisQuestion);// Define the minimum and maximum numbersvar minNumber =1;var maxNumber =10;// Only load random numbers onceif($.trim($(input1).val())==''&& $.trim($(input2).val())==''){// Create an array of possible numbersvar numbers =[];var i;for(i = minNumber; i <= maxNumber; i++){
numbers.push(i);}// Shuffle the numbers array
shuffleArray(numbers)// Load the first sub-question with the first number
$(input1).val(numbers[0]).trigger('keyup');// Load the second sub-question with the second number
$(input2).val(numbers[1]).trigger('keyup');}});// A function to shuffle arraysfunction shuffleArray(array){for(var i =array.length -1; i >0; i--){var j = Math.floor(Math.random()*(i +1));var temp =array[i];array[i]=array[j];array[j]= temp;}returnarray;}</script>