[Solved] One Random Page from Each Group, No Repetition


I have 3 groups of 6 pages. I want each respondent to get only 1 random page from each group. I have used the “Show a number of randomly selected pages from a survey” custom script which is given here: https://script.surveygizmo.com/help/article/link/show-a-number-of-randomly-selected-pages-from-a-survey

However, I want to make one crucial addition. You can visualize my groups of pages as follows:

Group 1 (A, B, C, D, E, F)

Group 2 (A, B, C, D, E, F)

Group 3 (A, B, C, D, E, F)

What I need to accomplish is that no respondent sees the same letter twice. The sequence of 3 pages they should see should look like ABC or BDF or CBD. But never ABA or AAC or BFF.

I have added the above mentioned script to the welcome page. This ensures that they get one page from the first group. I have then added the script to each of the 6 pages in group 1 and 2 to ensure they get one page from each following group.

Respondents see 3 pages, just like intended. But somehow I need to include a mechanism that ensures each page is from a unique letter category. 

Thank you for any suggestions.

seanfilidis selected answer

    Best answer


    I created 3 hidden values on the welcome page: Group1, Group2, Group3.

    Then I created a JavaScript on the welcome page. It created 3 arrays, each populated with the 6 letters from my original post (they are actually companies).

    I created 3 random variables, each to be populated with one item from each array. I used a loop to ensure the random variables were each unique.

    Then I used the page IDs for the hidden values to set them equal to the random variables.

    Then I set the page logic on each page to show only if the corresponding hidden value matched.

    The result is that each respondent will see 3 pages, one from each group, and it will never be the same company twice.

    Here is the javascript I used.

    var apology = [”Michelin”, “Nintendo”, “Energizer”, “KFC”, “McDonalds”, “Disney”];
    var promotion = [”Michelin”, “Nintendo”, “Energizer”, “KFC”, “McDonalds”, “Disney”];
    var partnership = [”Michelin”, “Nintendo”, “Energizer”, “KFC”, “McDonalds”, “Disney”];

    var randomApology;
    var randomPromotion;
    var randomPartnership;

    randomApology = apology[Math.floor(Math.random() * apology.length)];

    do {
    randomPromotion = promotion[Math.floor(Math.random() * promotion.length)];
    while (randomPromotion == randomApology);

    do {
    randomPartnership = partnership[Math.floor(Math.random() * partnership.length)];
    while (randomPartnership == randomApology || randomPartnership == randomPromotion);

    document.getElementById(“sgE-2790245-5-174-element”).value = randomApology;

    document.getElementById(“sgE-2790245-5-178-element”).value = randomPromotion;

    document.getElementById(“sgE-2790245-5-179-element”).value = randomPartnership;

    seanfilidis selected as best answer


      Question stats

      • Active
      • Views1974 times
      • Answers1 answer
      • Followers1 follower