This question is about the ARC JavaScript command: Utility.getRandomUnique.
I know there are two Utility random functions: Utility.getRandom and Utility.getRandomUnique. The one I mentioned first, Utility.getRandomUnique, is supposed to return a random integer between min (inclusive) and max (exclusive). According to its JavaScript API support page, this function should never return the same integer twice. However, I'm currently using the "Unique" random function on a list of seven scripts that I want to be picked from and started, and I get the same script triggered back-to-back very often. Is this function broken in ARC? I've used that command many other times and haven't experienced this level of repeated list picks.
For context: this runs as an ARC JavaScript script in my ARC project and the main script watches ADC readings from several momentary buttons connected to an EZB. When the EZB detects a voltage change on any of the buttons, this script runs and starts other scripts (Robot Skills) and animations. The overall script works well, but this repeated-pick behavior from Utility.getRandomUnique is frustrating. I can post the entire script if needed.
Any info is welcome.
Below is the section of a larger script that uses Utility.getRandomUnique. I reformatted the code for readability but did not change variable names or logic:
//-----------------------------------------------------------------------------
// This section will pause the already running "Personality Generator" & "Weather Loop" scripts.
// Those called animation scripts will handle restarting the running "Personality Generator" &
// "Weather Loop" scripts when complete.
// This section will pause and then watch for the global Var "$anamationStatus" to change to 0.
// 0 is set by the called animation scripts showing that they are complete. Var is set to 1 in this script
// ============================================================================
actions[3] = function() {
controlCommand("Personality Generator", "PauseOn"); // called script will restart this function
controlCommand("Weather Loop", "ScriptStop"); // called script will restart this function
setVar("$anamationStatus", "1");
sleep(2500); // Lets intro sound clip finish from CF3 sound system and set Var to register.
var animationList = [
"Attack",
"Danger! Danger!",
"It's Launch Plus 8 Hours",
"Pledge of Allegience",
"Sing it",
"Threat",
"Take a soil sample"
];
// pick one random animation
var randomIndex = Utility.getRandomUnique(0, animationList.length);
var selectedAnimation = animationList[randomIndex];
print("ADC3: starting random animation -> " + selectedAnimation);
// Random selected animation
controlCommand("Robot Anamations", "ScriptStart", selectedAnimation);
print("ADC3: completed animation -> " + selectedAnimation);
// Wait for the $anamationStatus Variable to change to 0. 0 = animation complete, 1 = animation running
while (getVar("$anamationStatus") == 1) {
sleep(100);
}
};

Utility.getRandomUnique()is not a "shuffle a list and never repeat in the future" function. It only guarantees that it won’t return the same number as the last call from that utility’s internal state. That means:So: it’s not broken - it’s just being used for a job it wasn’t designed to solve.
The better ARC approach
For a list of 7 actions, the proven method is:
Utility.getRandom()That gives you true no-back-to-back repeats for your list, which is what you actually want.
Recommended JavaScript pattern
Why this is better
Utility.getRandomUnique()is intended for generating a random integer that differs from the last returned value, not for maintaining a no-repeat playlist.One thing I noticed in your script
You have:
and later:
That variable name is spelled
anamation, notanimation. If that’s not intentional, it could create confusion later. Also, compare it consistently as a string or number. In ARC JavaScript, I’d keep it consistent:If you want zero repeats until the whole list is exhausted
That’s a different behavior: a shuffle bag approach. ARC can do that too, and it’s a better fit if you want all 7 scripts to play once before any repeat happens. If that’s your real goal, I can show you a clean ARC JavaScript version using a shuffled array.
Quick question
Are you trying to avoid only back-to-back repeats, or do you want every animation to play once before any repeat happens?