# Show random subsample of groups

1 Monat 1 Woche her #192667 von lobster
Hi there,

I have a survey with 6 groups and want each participant to see randomly chosen 3 of them. I tried putting them all in the same randomization group and using a counter to limit the number shown to 3. However this counter does not behave like I would expect it to.

Anyone know a good solution on how to show a random sample of groups only?

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

LimeSurvey Partners
1 Monat 1 Woche her #192670 von Joffm
Hi, lobster,

1. with javascript
create a question of type "short text" and enter this snippet
```<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;
}

// Fill the array
var arr = [1,2,3,4,5,6];
arr = shuffle(arr);
anumbers = arr.slice(0,3).join('');
\$('#question{QID} input[type="text"]').val("#"+anumbers);
\$('#question{QID}').hide();
});
</script>```

You will get a string like

Now you can display your groups using the relevance equation:
group 1: strpos(Q1,"1")>0
group 2: strpos(Q1,"2")>0
...
Now you see the reason for the "#": To be able to distinguish between the index "0" and the result "0", meaning "not found".

2. Without javascript
There are only 20 different combination of 3 groups out of 6.
1: 1,2,3
2: 1,2,4
3: 1,2,5
4: 1,2,6
5: 1,3,4
6: 1,3,5
7: 1,3,6
8: 1,4,5
9: 1,4,6
10: 1,5,6
11: 2,3,4
12: 2,3,5
13: 2,3,6
14: 2,4,5
15: 2,4,6
16: 2,5,6
17: 3,4,5
18: 3,4,6
19: 3,5,6
20: 4,5,6

Create a random number 1-20 and display the groups accordingly.
Group 1: random<11
Group 2: (random<5) OR ((random>10) AND (random<17))
Group 3: (random==1) OR ((random>4) AND (random<8)) OR ((random>16) AND (random<20))
...

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
##### Anhänge:
Folgende Benutzer bedankten sich: gabrieljenik

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

1 Monat 1 Woche her #192676 von Joffm
3. Use QCode.gseq
https://manual.limesurvey.org/Expression_Manager_-_presentation#Access_to_variables
Set the relevance equation of each group to
"G1Q1.gseq lt 4"
"G2Q1.gseq lt 4"
where GxQ1 is a question in this group which is aleays displayed.
...
As you read in the manual the count starts at "0". So you have to adapt the "4" of my example.

Joffm

I always take for granted that the groups have the same randomization group name.

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Bitte Anmelden oder Registrieren um der Konversation beizutreten.

1 Monat 1 Woche her #192694 von okalmus
Hi Joffm,

thank you very much for all your help. I went with the random number method, as it seemed the most straightforward to implement right away. I will look into the other options for future reference for sure.

Thanks again.

Bitte Anmelden oder Registrieren um der Konversation beizutreten.