Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/15149c8a46450f0efc0195ab2b92df02 to your computer and use it in GitHub Desktop.
Save trycf/15149c8a46450f0efc0195ab2b92df02 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
/**
* Randomly shuffles an array of strings using Fisher-Yates algorithm.
*
* @param strings Array of strings to be shuffled
* @return Array of strings in random order
*/
public array function shuffleArray(required array strings) localmode=true {
var shuffled = strings.clone(); // Clone to avoid mutating original array
var i = 0;
var j = 0;
var temp = "";
for (i = shuffled.len(); i > 1; i--) {
j = randRange(1, i); // CFML arrays are 1-based
temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
return shuffled;
}
extrasIncudeFileNames = [
"social-media-pack",
"shazam",
"audio-mack",
"beatport",
"store-maximizer",
"dolby",
"legacy"
];
shuffledArray = shuffleArray(extrasIncudeFileNames);
writeDump(shuffledArray);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment