How can I randomize from a set, and ensure no duplicates? | XM Community
Question

How can I randomize from a set, and ensure no duplicates?

  • 25 September 2020
  • 1 reply
  • 29 views

I am programming a survey where the first condition involves 4 images ordered in a fixed way, which is easy to program. The second condition, however, involves randomizing the first three images of every 4 image set, leaving the 4th image fixed. Both conditions are dealing with 60 pictures, so my question is how can I avoid duplicating images in the second condition? If I simply set the images to randomly come out of a common bank of images, I get many duplicates. Is there a way to pick randomly from the group, and simultaneously mark that image as to not pick it again?

thanks


1 reply

Userlevel 4
Badge +4

Not sure I have enough information to help you here but if you can use javascript (and HTML), it could be quite a neat solution.
If you have an array of 60 image ids, all you do is split it into groups of 4 (or you can pre-load your data in JS so as to have different objects that contain the 4 images) and then only randomize the first 3. Then you use HTML to plug in the image IDs into any relevant question (you can use embedded data if the JS and the HTML are on different pages or you can straight up set HTML via JS if they are on the same page).
If you provide a minimally reproducible example of the problem, some image data and desired output, I can perhaps help more (.qsf works best).

Leave a Reply