Word randomizer script
Hello,
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?
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?
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.
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.