TOPIC: Showing a random subset of all possible groups

I'm trying to set up a questionnaire that will display only a random subset of all possible groups to participants, and I'm wondering, is it possible to do this with Expression Manager (or a combination of javascript and EM)?

Within each group is a number of question variants, only one of which will be displayed to participants, selected at random. I found this to be very easy to implement with EM, thanks to this example.

Displaying only a subset of possible groups is more difficult since multiple groups need to qualify as relevant, and the selection of each group needs to be independent of the other groups. That is, each group can't simply occur with a fixed selection of other groups; the probability of occurring with any other group must be equal.

I'm currently using an unsatisfactory work-around, in which I have a hidden equation question corresponding to each group that randomly generates 1 or 2, with the relevance of each group set to 1. This means that each group has 50% probability of being displayed to any given participant, and that each participant will see, on average, half of the possible groups, but also that some participants could end up seeing quite a bit more/less than that, which is undesirable.

I thought that a possible solution would be to have a hidden question that randomly shuffles an array of integers (corresponding to the total number of groups) and then takes a slice of that shuffled array. Each group would have a unique relevance value corresponding to an integer from within this array, and would be set to display if it's value is among the slice generated. This sounds simple enough to explain, but as I'm nearly programming illiterate, I don't know how difficult it is to actually implement. The first part I could probably manage but I don't if the second part is within the current capabilities of the relevance equations to specify. Is it possible, and if so, how?

If you've read this far, many thanks for your patience, please forgive my ignorance, and many apologies if I've accidentally left out any important details. Any reply would be much appreciated.

The administrator has disabled public write access.

JavaScript is currently disabled.Please enable it for a better experience of Jumi.

Ok, no-one's replied, so I'm guessing my question was problematic in some way, but it would really help to know what way that was. Please, any feedback at all would be really helpful; e.g. "I don't understand what you're asking", or "That's not possible", or "That is possible but I'm not going to explain how", or "It's really obvious and you should easily figure out the answer", or even "I don't know".

Incidentally, I'm not the only one who's asking this type of question. This post by Iosononando is essentially about the same thing.

Placing this script in the source of a multiple-numeric question will shuffle an array of group numbers and then load the numeric inputs with the corresponding array values. (So, if for example, you only want to capture the first 4 random numbers, use 4 subquestions it the multiple-numeric.)

You can then use relevance/conditions to display following groups depending on the multiple-numeric values.

Thanks very much for your reply, and for the javascript code - it works perfectly.

However, I'm still having trouble using the multiple-numeric values to control group displays. I tried an example with 10 groups, and specified 10 subquestions in the multiple-numeric, then set the relevance of following groups to display if the corresponding subquestion returned a value of less than or equal to 5. The effect should have been to display only 5 random selected groups, but it doesn't work. Instead, they all display, despite the survey logic coming out clear.

I tried the way you initially suggested but couldn't figure out to define an appropriate variable (the multiple-numeric question code was reported to be "undefined" but the subquestion codes were fine).

I'm attaching a copy of my survey - perhaps someone could take a look and see if it's an easily fixable problem?