2

We're using CrowdFlower in tandem with Amazon Mechanical Turk. Our questions have the same set of answers to choose from, so we'd like to randomize the order in which they appear, in order to keep users alert and hopefully dissuade them from cheating.

We want to be able to insert a script into the CML (CrowdFlower Markup Language) Documentation that could be applied to all the questions. We think inserting some JavaScript would be the right way to go. Any tips would be welcome.

szabgab
  • 6,202
  • 11
  • 50
  • 64
jeunefille
  • 21
  • 3

2 Answers2

2

You can achieve this with a small snippet of javascript. All you'll need to do is add a class="rando" attribute to the cml:radios or cml:checkboxes tag that you want to randomize, and place the following code in the javascript portion of the advanced editor (this assumes you have fewer than 10 choices in your cml:radios or cml:checkboxes tag):

$$('.cml_field.rando input').sort(function(a,b) {
   return Math.round(Math.random()*10) - 1 
}).each(function(o) { 
   o.getParent('.cml_row').inject(o.getParent('.cml_field')) 
})
  • Do you know if the following is possible: Say I have 5 radio buttons (a,b,c,d,e) and I want to randomize them so that ab stay together and cd stay together. – jeunefille Jun 28 '12 at 17:35
  • It's possible but rather tricky. The simplest way would be to modify the sort function above to return the same value for the fields you want to stay together. Something like: `function(a,b) { if(a.get('value').match(/a|b/)) { return 1 } else { return Math.round(Math.random()*10) - 1 } }` – Chris Van Pelt Jun 28 '12 at 19:26
  • Here's what I'm trying to do: Make AB the same class. Let replace=Math.floor(Math.random()*2). If replace==1, then replace the label on A with that on B, and vice versa. My question is, how can I access the labels of radio buttons so they can be changed? $$('.cml_field.myClass input').replace("A","B") doesn't seem to work – jeunefille Jun 28 '12 at 21:45
  • Okay, here's what I've figured out how to do: First, I do one sort to totally randomize the choices. Then, I do a second sort to send "a" and "b" to the top of the order. Finally, I do a third sort to send "e" to the bottom. The problem is, I want to be able to vary whether a and b go first or c and d go first for each question. Is there a way to access each unit on the page individually, instead of altogether? Thanks! – jeunefille Jun 28 '12 at 23:44
1

You can also use the random Liquid filter:

{% capture my_value %}{{ 3 | random }}{% endcapture %}
{% case my_value %}
{% when "1" %}
  One
{% when "2" %}
  Two
{% when "0" %}
  Zero
{% endcase %}
mrgordon
  • 130
  • 1
  • 2
  • 7