> For the complete documentation index, see [llms.txt](https://synoint.gitbook.io/survey-library/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://synoint.gitbook.io/survey-library/source-code-api/multiple-choice-reference/randomization.md).

# Randomization

{% hint style="info" %}
Please note that **Survey’s built-in randomization** is not compatible with the **advanced randomization codes** provided in this tutorial. To enable advanced randomization for your multiple choice question, import the library as described in the [Getting started](/survey-library/getting-started.md) section.
{% endhint %}

Once you have completed the main steps, you will need to modify the parameters in the provided template snippet to apply the changes.

<table><thead><tr><th>Variable</th><th>Example</th></tr></thead><tbody><tr><td><strong><code>question_code</code></strong><br><br>The code of the multiple choice question you want to configure</td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
<strong>    question_code: "Q1"
</strong>});
</code></pre></td></tr><tr><td><strong><code>schema</code></strong> <br><br>This variable represents an <mark style="color:blue;"><strong>open text field</strong></mark> where answer codes will be stored. It is only required if you plan to use this question to <mark style="color:red;"><strong>filter</strong></mark> or <mark style="color:red;"><strong>randomize in the same order</strong></mark>. Remove it if not needed.<br><br><span data-gb-custom-inline data-tag="emoji" data-code="1f4a1">💡</span> Use a descriptive name for the schema that indicates it is associated with a specific question code, such as<br><code>Q1_SCHEMA</code> or <code>Q1xSCHEMA</code><br><br><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> <em>The open text should be placed in the same page of the multiple choice.</em><br><br><img src="https://3256950692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8ViByLqKSYWJoXIHUUnY%2Fuploads%2F3e3ClosuOgnE57zgEGh1%2Fimage.png?alt=media&amp;token=a138db89-fc20-45ee-bae0-891477657d21" alt=""></td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
<strong>    schema: "Q1xSCHEMA"
</strong>});
</code></pre></td></tr><tr><td><p><strong><code>randomize</code></strong> <br></p><p>Here we define settings for randomization. If not needed, just remove this entire block code and skip this tutorial <span data-gb-custom-inline data-tag="emoji" data-code="1f44d">👍</span></p></td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
    schema: "Q1xSCHEMA",
<strong>    randomize: {
</strong><strong>        
</strong><strong>    }
</strong>});
</code></pre></td></tr><tr><td><strong><code>randomize</code></strong> -> <strong><code>filter_schema</code></strong> <br><br>This variable allows you to randomize answer options in the same order as a previous question by using its schema.<br><br><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> <em>If you choose to use this feature, you can skip the rest of the configurations described below this row.</em></td><td><pre class="language-javascript"><code class="lang-javascript">multiple_choice({
    question_code: "Q1",
    schema: "Q1xSCHEMA",
    randomize: {
<strong>        filter_schema: "Q0xSCHEMA",
</strong>    }
});
</code></pre></td></tr><tr><td><strong><code>randomize</code></strong> -> <strong><code>answer_groups</code></strong><br><br>This variable represents a list of answer codes that you want to group together for randomization. The answer codes should be wrapped inside brackets [] and separated by commas.<br><br><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> <em>Any remaining answer codes that are not included in a group will be treated as anchors.</em></td><td><pre class="language-javascript"><code class="lang-javascript">/* Using one group */
multiple_choice({
    question_code: "Q1",
    schema: "Q1xSCHEMA",
    randomize: {
<strong>        answer_groups: [
</strong><strong>            [1, 2]
</strong><strong>        ]
</strong>    }
});

/\* Using multiple groups \*/
multiple\_choice({
question\_code: "Q1",
schema: "Q1xSCHEMA",
randomize: {
answer\_groups: \[ <strong>            \[1, 2], // group 1 </strong><strong>            \[3, 4]  // group 2 </strong>        ]
}
}); </code></pre></td></tr><tr><td><p><strong><code>randomize</code></strong> -> <strong><code>randomize\_groups</code></strong><br><br>This variable determines whether or not answer groups should be randomized after the elements inside them have been randomized. </p><p></p><p>If set to <mark style="color:blue;"><strong>true</strong></mark>, both the elements within the groups and the groups themselves will be randomized. </p><p></p><p>If set to <mark style="color:red;"><strong>false</strong></mark>, only the elements within the groups will be randomized.</p></td><td><pre class="language-javascript"><code class="lang-javascript">multiple\_choice({
question\_code: "Q1",
schema: "Q1xSCHEMA",
randomize: {
answer\_groups: \[\[1, 2]], <strong>        randomize\_groups: false </strong>    }
}); </code></pre></td></tr></tbody></table>
