Structure shuffling

dimitri's picture

Hi everybody,

I am facing a rather simple project where i must create a slideshow in random order.

The main goal is being able to shuffle the structure so that every picture is displayed once in the directory loop. Using a random patch the same picture sometimes get picked up twice in a row.

There are two solutions for generating a shuffled plist file and use it incrementally to select the source image:

1/ with a database software (easy for me but a pain in the long run)

2/ or dynamically from within QC by shuffling the structure

Not worth mentioning the second solution is the right one, but unfortunately i don't know enough javascript to make it by myself.

I'd be very glad to get some help on this one… Thanks!

usefuldesign.au's picture
Re: Structure shuffling is fun to debug

People don't seem to write your JS code for you on this site I've found. So you have to persevere like me until it sinks in a bit ;).

Make use of Cybero's JavaScript Guide

I've struggled with JS so out of compassion here is some pseudo-code. Have a go its the only way you'll learn and JS is so useful in QC.

Function inputs pics (the number of items)
      outputs an array (of length = pics)
 
 
//declare a list array and a finished random array
var list=new array();
var randomOrderList();
 
// iterate to make it a list of numbers
for (i=0; i <pics; i++) {
   list [i] = i }
 
// iterate through the list randomly selecting items
for (i=0; i <pics; i++)
 
   n  = Math.random() * list.length;
   randomOrderList [i] = list [n];
 
// remove the item so it's not selected again (various options here like splice, sort, pop methods, study Array section in Cybero's JS Guide)
   var a = list.splice ( n , 1 );
 
return result

I'll post some hints/code in a few hours if your still struggling.

dimitri's picture
Re: Structure shuffling is fun to debug

Thank you usefuldesign,

I know my demand was a bit pushy, slightly overworked in here :)

A friend pointed me to this page as well http://www.javascriptkit.com/javatutors/arraysort.shtml

… and yes, i am definetely having a go at JS as soon as pressure releases the grip …

Once my composition works i'll drop it here, since it's a very general concept and can be useful to anyone.

thanks for your reply!

usefuldesign.au's picture
Re: Structure shuffling is fun to debug

I've done the comp to make sure, most of the time was in the debugging (nothing new there), I'll post when you have!

As for the randomising method, it's not first class but is a basic start. See Yanamano's recent thread about rand seed generation for more ideas.

usefuldesign.au's picture
Re: Structure shuffling

He's comp with script.

PreviewAttachmentSize
Random shuffle thru struct.qtz15.43 KB

dimitri's picture
Re: Structure shuffling - THANK YOU

First time here in months!

Worked so much i couldn't catch up with what happened in the QC world, so it's only this morning that I find your helpful comp!

Sorry for not having said thanks before! I'll study it now :)