- Posts: 8
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } $(document).on('ready pjax:scriptcomplete',function(){ // Fill the array var arr1 = [1,2,3,4]; var arr2 = [5,6,7,8]; arr1 = shuffle(arr1); arr2 = shuffle(arr2); an1 = arr1.slice(0,2).join(','); an2 = arr2.slice(0,2).join(','); $('#question{QID} input[type="text"]').val("#"+an1+an2); $('#question{QID}').hide(); $('#ls-button-submit').trigger('click'); }); </script>
but you only get two randomly selected question of 1A, 1B, 1C and 1D
and two randomly selected question of 2A, 2B, 2C and 2D.
But how do you get the random order of these 4 questions?
If you do it like this the order will always be 1X, 1Y, 2X, 2Y,
but never 1X, 2Y, 2X, 1Y
@Joffm
Your solution works perfectly, but it is getting even more complicated now, as requirements have changed
I still have my 2 Groups with 4 Questions each:
Group1: A1, A2, A3, A4
Group2: B1, B2, B3, B4
Now I still want to randomly chose 2 out of each group and display them in random order, BUT: numbers 1-4 have to be in each set. E.g. A2-B4-B1-A3 or A1-B2-B4-A3.
Is that also possible with your method??
Thanks!