search
date June 21st, 2008  written by E.Hallander  categories Actionscript 3.0

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) (261 downloads)



Feel free to check out the feed or leave a trackback from your own site.

4 Responses to “Get a unique random value or position from an array in AS3”

Post A Comment

Site served by; centOS5, mysql 5.1 & php 5.2.6
'If it ain't broken, it must at least be due for a service?'