Links

Randomize Field Option Order

Randomize the order of options in a field (e.g. dropdown)

Overview

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

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);