Word randomizer script

Advanced Renamer forum
#1 : 21/08-20 20:00
Posts: 1

I am looking for a script that can randomize a string of words to add to the file name.
In a previous forum thread I found this script:

var colors = ["Red", "Green", "Blue", "Cyan", "Yellow", "Purple"];
return colors[Math.floor((Math.random() * colors.length))];

This works great, except it only outputs one of the colors.
This script can output the entire randomized string in a Javascript console, but I dont know how to adapt it to Advanced Renamer:

const shuffle = array => array.sort(() => Math.random() - 0.5).toString()
const colors = ["Red", "Green", "Blue", "Cyan", "Yellow", "Purple"];
console.log(shuffle( colors ))

How can the scripts be adapted to work?

21/08-20 20:00
#2 : 22/08-20 11:03
David Lee
David Lee
Posts: 662
Advanced Renamer does not support JavaScript ES6 extensions so you will have to use the original verbose function syntax:

function shuffle (array) {
return array.sort(function(){return 0.5 - Math.random()});
colors = ["Red", "Green", "Blue", "Cyan", "Yellow", "Purple"];
app.log(shuffle( colors ));

app.log writes output to the "JS Console" (main menu item).

Note that this will only work if you have at least one item in the List.

22/08-20 11:03