|
Random number sequenceHoi, I made sort of a slideshow with a folder of picts. Now there playing in order. But i want them to play random from lets say 1 to 10 but showing every pict only once. than starting over and show all 10 in a different random sequence. I can't seem to ficker it out. Can somebody help me? It can't be that hard? Thx Tijn
|
/me dusts off the old math book
What you're wanting is a "permutation", not exactly a "random sequence" -- a random sequence can reuse items, while a permutation is just a reordering.
to do this, you'll want to generate a list of indexes (0, 1, 2, 3, 4, 5, ..., n), and then Swap random indices. This is quite simple with javascript:
Hope that helps
I need this thing in a lots of situation, so i made a plugin: http://code.google.com/p/cogerandom/
There's an alternative method at the bottom of this page. http://www.javascriptkit.com/javatutors/arraysort.shtml
a|x
isn't that unstable (as in, depending on the sort algorithm it could plausibly never complete)? not at all likely to ever happen, but the runtime isn't necessarily guaranteed.
Thanks everybody for all your quick replys.
The plugin is just what i needed.... Sory but java script isn't realy my thing. Can't seem to get my head around text programming.
Thanks again
Tijn
this plugin has a memory leak; see attached composition (running with VBLSync disabled helps make it apparent more quickly)
you should release workarray in disableExecution, not stopExecution. (not sure how to commit to google code)
Ahh, i fixed it, thanks for your help!
Another Javascript way to do it — for when you decide you'd like to learn JS. QC is so much more interesting with a bit of JS.