Randomizing order of elements shown in a context field

I have a deck of cards to study Japanese kanji and vocab (specifically for 漢検2級). In several of these problem sets, a list of words is presented for each question that you pick the answer out of and then write the kanji (example). In my cards I wanted to have the list of words be randomized so I wasn’t memorizing the position of elements. I had Claude write the Javascript below to help me with this.

I can’t be the first to run across this issue of wanting to have certain elements on a card be shown in random order. Is there a standard add-on or function available that I’m not aware of that does the same thing?

<script>
(function() {
    // 1. Get the element containing the list
    var container = document.getElementById('scramble-list');
    if (!container) return;

    // 2. Read the raw text from the field
    var text = container.textContent.trim();
    if (!text) return;

    // 3. Split by standard US comma (,) OR Japanese comma (、)
    // The regex [,\u3001] matches either character
    var list = text.split(/[,\u3001]/);

    // 4. Clean up whitespace from each item
    list = list.map(function(item) {
        return item.trim();
    }).filter(Boolean); // Removes empty items if there are trailing commas

    // 5. Fisher-Yates Shuffle Algorithm to randomize the array
    for (var i = list.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = list[i];
        list[i] = list[j];
        list[j] = temp;
    }

    // 6. Join them back together. 
    // You can change ', ' to '、' below if you prefer Japanese commas in the output.
    container.textContent = list.join('、');
})();
</script>

If you’re looking for ways to randomize multiple-choice order [and you’re already aware of the reasons to avoid multiple-choice in Anki] – here’s a good compilation of options:

The function AI gave you pretty much is the standard way of shuffling elements in the web. I would expect most of the templates above using a variation of it. The code can be shortened quite a bit, so you shouldn’t take its current length as a measure of the method complexity, which is already minimal.
If you are looking for a way to make this function more general and compact to be copy-pasted between card templates, it can be improved in that regard. If you just need something for a one-time use in your specific case, it should be good to go as is.