Btw I over-complicated it, you don't need a function or an array to achieve the shuffle, try this :
With your code, if there are four instances of the sprite, they will receive frames 0–3. As I understand it, there are more than four frames in the animation, and OP wants to assign random frames without repeats.
Yeah, there are many ways to do this, even in C2, but none of them are very straightforward.