Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Randomly chose 2 questions out of each question-group

  • diegestaltung
  • diegestaltung's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago - 4 years 3 months ago #213562 by diegestaltung
Hi!

I have 2 Question-Groups with 4 questions each. Now I want to randomly chose 2 questions out of each group and display the resulting 4 questions in random order.

Thanks to the answer from @Joffm in this thread  forums.limesurvey.org/forum/can-i-do-thi...questions-out-of-100 I managed to randomly chose 4 questions out of my 2 groups, but sometimes it shows e.g. 3 out of group 1 and only 1 of Group 2. But it should always be 2 out of each group.

Is this possible?
(  I am using the cloud version)

Thanks!
Last edit: 4 years 3 months ago by diegestaltung.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #213569 by Joffm
Okay, this is different, as we cannot have two "randomization groups"

1. The very basic way:
Knowing that there are only 36 different combinations, from
1: A1 A2 - B1 B2   
2: A1 A2 - B1 B3   
3: A1 A2 - B1 B4   
4: A1 A2 - B2 B3   
...
36: A3 A4 - B3 B4
you could create a random number from 1 to 36
and display the four questions
And all 8 questions are in the same randomization group.

2. Create a question of type "short text" ("Q0")with this javascript snippet.
Here you select two numbers out of each group
Code:
<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>

Now the relevance equation of each question is "Does the string contain this number?"
Function "strpos"

Question A1: strpos(Q0,"1")>0
Question A2: strpos(Q0,"2")>0
...
Question B4: strpos(Q0,"8")>0

All questions have the same randomization group name.

 

File Attachment:

File Name: limesurvey...7465.lss
File Size:23 KB


Joffm​​​​​​​

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • diegestaltung
  • diegestaltung's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #213572 by diegestaltung
Replied by diegestaltung on topic Randomly chose 2 questions out of each question-group
Wow :). That works! I admit that I didn't fully understand it, but I imported the file and it works just perfectly! MANY THANKS
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #213575 by Joffm
I can explain it, but in German.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • diegestaltung
  • diegestaltung's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #213576 by diegestaltung
Replied by diegestaltung on topic Randomly chose 2 questions out of each question-group
Dann würd ich es sicher auch besser verstehen :)))
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #213585 by holch
I think there is an even easier way. Without the need of any programming.

Create 4 groups instead of 2.

E.g. 1A, 1B, 2A, 2B.

Put the 2 of the 4 questions of the original Group 1 into 1A and 2 into 1B. Give these questions the same "randomization group name", e.g. "Group1".

Do the same for the second group.

What happens? The 4 questions will be randomly distributed over the two groups 1A and 1B. So far, so good. Once that works, you hide group 1B. This means the respondents will only see 2 of the 4 questions.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #213586 by holch
OK, I am just seeing that in the link you post that principal was used. But I guess the problem was that you only used 2 groups with questions. In your case you would need to use 4 question groups and hide 2 of them to simulate what you want to do.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
  • diegestaltung
  • diegestaltung's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #213602 by diegestaltung
Replied by diegestaltung on topic Randomly chose 2 questions out of each question-group
@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!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #213603 by Joffm
Hi, @holch,
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

Or am I confused? Always remember my age.

Joffm
​​​​​​​

 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 3 months ago #213611 by holch
OK, so the groups among each other should also be randomized?

I did not read this into the first question.

But now the requirements have changed even more.

Actually, in my opinion with the new requirement it is not 2 groups with 4 questions, but 4 groups with two questions each.

But I don't think that it is possible with this "easier" non Javascript approach anymore.

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


Well, the two questions of each group would always be together, either at the beginning or at the end. You would not get a completely random option where each question could be at any of the 4 possible positions.

Group1: A1, A2, A3, A4
Group2: B1, B2, B3, B4

You could get combinations like

- A1, A3, B2, B1
- B4, B1, A2, A4

But you could not get something like that:

- A1, B2, A3, B1

Anyway, with the new requirement that each number must be represented and each letter needs to be there twice, this approach won't work anyway.

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
  • diegestaltung
  • diegestaltung's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #213619 by diegestaltung
Replied by diegestaltung on topic Randomly chose 2 questions out of each question-group
Thank you @holch, maybe I didn't describe it clear enough in the first post, but yes, it is as @Joffm understood, the final order should be randomized :(.
The topic has been locked.
  • diegestaltung
  • diegestaltung's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 3 months ago #213620 by diegestaltung
Replied by diegestaltung on topic Randomly chose 2 questions out of each question-group
Hmmm, I thought I just solved the new requirement myself, by just giving A1 and B1 the same randomization group name, also A2 and B2 and so on… but unfortunately now it happens that the same question is shown twice :(

@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!
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose