# Randomize Field Option Order

## Overview

In this example, the order of options in the following dropdown field will be random each session.

<figure><img src="/files/52UcTeZ3oclj8J1C0ZKb" alt="" width="375"><figcaption></figcaption></figure>

## Rule Logic

This rule should run when the step of the form with the dropdown field is loaded.

The logic gets the existing field options, shuffles them, and updates the field with the newly ordered options. In this example, the dropdown field ID is `RandomOptions`

```
/* Randomize array using Durstenfeld shuffle algorithm */
function shuffleArray(array) {
    const newArray = [...array];
    for (var i = newArray.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = newArray[i];
        newArray[i] = newArray[j];
        newArray[j] = temp;
    }
    return newArray;
}

RandomOptions.options = shuffleArray(RandomOptions.options);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.feathery.io/platform/build-forms/advanced-logic/examples/randomize-field-option-order.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
