Demo: Randomize Table Rows

tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
edited February 2013 in Working with GS (Mac)
I got a little tired of using a method for extracting random table rows (e.g. randomly picking an image from a list of images, a question from a list of questions, etc.) that deletes a table row after choosing it, so I hit up Google and found a nice little algorithm. The source of the algorithm and the source of the time stamp loop (which I've posted about previously) are in the actor's notes.

Basically, this takes a table (currently 10 rows and only 1 column, but adaptable as needed) and randomly shuffles the rows "in place." I have not tested it extensively so if anyone has any criticisms or improvements, I'm all ears.

Comments

  • epicstagepicstag PRO Posts: 132
    edited February 2013
    This is great. Thanks for this!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    currently 10 rows and only 1 column, but adaptable as needed
    If you need more rows, you'll need to add them to the DisplayText behavior. In that behavior, you'll see that I have concatenated each row like this:

    tableCellValue( game.|T| Values ,1,1).."\n"..
    tableCellValue( game.|T| Values ,2,1)

    The .. concatenates or joins expressions, while the "\n" adds a new line.

    You could, of course, create a separate loop to concatenate all of the row data into a single text attribute and then just display that attribute.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @tatiang -- That's pretty slick! Thanks for sharing.
  • ChakkuChakku Member Posts: 1,513
    @tatiang

    Great!- thanks for sharing.

    Chakku
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Nice one, @tatiang !
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Thanks, guys! Glad you're finding it useful.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    Excellent, @tatiang, (I must have missed this post at the time). I have Awesomed you! :-)

    Still trying to get my head around it tho' , to understand what's going on with your impressive programming.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2013
    @gyroscope While I'd love to take all the credit, I didn't come up with the idea. I just translated an algorithm that already existed (http://en.wikipedia.org/wiki/Knuth_shuffle) into a GameSalad project file. I didn't spend a lot time trying to understand the algorithm... I just googled ways to randomize data and then implemented what looked like the easiest one. :D
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    OK, still good work then in the translation, so still awesome in my books! And yes, at first glance, it all looks a bit head-scratching... :-)
Sign In or Register to comment.