Admittedly, this is nothing fancy like crazy fireflies! Just a small auxiliary class I wrote just now because I needed it in a project. I call it Shuffler. :)
What it basically does is to generate either a random position in the array, or return the value at that position, but keeps it unique (ie: no value will appear twice). It’s super lightweight and has close to no commenting whatsoever! haha!
Quick syntax:
import com.utils.shuffler;
shuffler.addSource(array_with_values);
trace(shuffler.getUniqueValue());
Or, if you just want the position in the array returned (better performance wise)
import com.utils.shuffler;
shuffler.addSource(array_with_values);
trace(shuffler.getUniquePosition());
You can download the class files and example FLA by clicking here (8Kb) (311 downloads)


June 22nd, 2008 at 5:42 pm
usefull little class, only downside as I see it, is that it destroys the source array…
I wrote a little function in a project I’ve been working on, it’s the same kind of thing as your class, you can check it out here… it’s a extract from a class and it’s very messy but it might be interesting
June 22nd, 2008 at 5:51 pm
yeah it does destroy the source array :P
Nice catch. I didn’t really test this, just posted it late yesterday. Updated the archive haha. Thanks
August 19th, 2008 at 4:58 am
Hi Eric!
Great class! I’ve made some small mods for my custom usage:
1. Removed static to enable instance based usage (I need different shuffle bags)
2. Added auto feed option, so it can be re-fed when array empties
Cheers,
Tom
August 19th, 2008 at 5:00 am
Also there’s a nice, simple and quick way to clone an array (check http://agit8.turbulent.ca/bwp/)
[code]
var copy:Array = sourceArray.concat();
[/code]