|
Sorting a structure randomlyHi Guys! this is my first post. So forgive me if the question could seem stupid I have a directory scanner that retrieve me the list of movies in a specific folder. I'd like to "randomize the order" of that list, so every time i trig the structure, i can scramble the order. I've tried with javascript with something like this
PHP Code:
function (__structure out) main (__structure input){
if(input !=null){
var result=new Object();
result.out=input.sort(function(){return (Math.round(Math.random())-0.5));
return result;
}
} Any solution??? Thanks |
This could easily be done with a multiplexer and a relatively short list of files.
Then again, you might have a lot of movies, who knows :-) ?
How's about running an LFO or if you want to go really quickly, a random number patch [Animation] to the indexing of that directory structure?
See attached.
dude - love that little avatar icon of yours - but you really need to sort out your Kineme link, which like many another I've found points to kineme's domain, because it has been incorrectly entered as
http://kineme.net/users/bikthefellas.wordpress.com
, when you mean to point to your actual wordpress setup [ which looks like it's still W.I.P, unless I'm much mistaken].... or using my little plugin for getting random numbers of indexes: http://code.google.com/p/cogerandom/downloads/list
I can build an example patch later, but at the moment i'm on a windows machine...
yeah, good call :-)
BTW, you could always set the timebase of the LFO or Random patch to use patch or system time, that would spice things up even more :-) .
double post in error
sorry dude! ;) i made a mistake between personal URL an working URL ;) (i'm feeling like the newbbie that i'm ;)
just provided to correct the mistake
It's a great example of using the LFO for randomizing...but it's not what i need :(
i'd like just to sort randomly that list and then keep using it as a structure.
Something like the Structure sort object in QC...
heres some javascript code that gives you a structure of randomly sorted indices.
the cogeRandom patch takes a similar approach but it will just return one index instead of a structure of them. it gives you a new one on each rising edge at the "new number" input port. it will return -1 when it uses up all the indices (then you need to reset it).
i wonder why something like this is not in the description of the patch ;).
edit:
had the first code in some composition, but this should do exactly what you need.