Randomly Distribute Table Contents - Plz Help

Hi gang, I'm trying to distribute the values from one table, split into two different tables - randomly and without duplication. So if there are 20 rows of data in table1, then table2, & table3 will acquire 10 new rows each. Table 1 will go back to 0 rows. (if there are odd rows, it will just distribute an odd number to one of the tables.)

I was actually able to get this to work with my tangled code, however it only works for one transfer per table for some reason, I can't get it to go all the way to completion.

How would you do it? Thanks.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You could use my randomizer demo and just set the row counter to 1-10 and 11-20 instead of 1-20. Use two loops or get fancy and do it in one!

    http://forums.gamesalad.com/discussion/53553/demo-randomize-table-rows

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • BrackAttackBrackAttack Member Posts: 22
    Fancy! I'll play with it when I get back to the computer in a bit. I wonder, in my case: table 1 will be variable (example was 20), but it will actually change in size. Table 2 & 3, will have rows of data already and will need to add the new rows on.

    I like your approach to randomizing. I had been using the other way to randomize, seemingly successfully. But my biggest issue seems to be figuring out how to split and transfer half the table into the two other tables.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You can use variable row numbers. In my demo, self.n is set to the number of table rows, but if you have 19 rows, you would set it to ceil(#rows/2), which is 10 and then in a separate loop, you would set it (or rather set self.n2) to #rows. That should work for any number of rows.

    The demo counts down from the number of rows, so you'd need to stop one loop at the first row (when self.i>1) and stop the other loop at the halfway point (when self.i2>ceil(#rows/2)+1).

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • epicstagepicstag PRO Posts: 132
    I use your demo quite extensively in my upcoming app @tatiang I really appreciate you posting that!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @epicstag Great to hear! Glad it was helpful.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • PaxPaxPaxPax Member Posts: 106
    Woh, stumbled on this thread. I am making a game and this 'logic' will more than come in handy. Thanks so much!! :)
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2013

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • BrackAttackBrackAttack Member Posts: 22
    edited March 2013
    Just an update:
    I've been playing around with it a bit. I changed the reset game button and put the whole time-stamp loop randomization into a rule 'if attribute game.button = true then randomize, And had the loop change game.button back to false when done. But I noticed that the randomization doesn't seem to be as robust now and I am seeing a lot of dominant repeats.

    I should note that I'm really not very clever, so getting my head around some of this stuff takes me awhile.

    Another Fail I managed: I created two new tables: |T| RandomHalfA and |T| RandomHalfB, with the simple goal of splitting the table |T| Values between the two new tables. I think I did what you suggested: I had one actor do the ceil(#rows/2), and stopped one loop at the first row (when self.i>1) and assigning the values to one of the new tables, and then had a second actor stop the other loop at the halfway point (when self.i2>ceil(#rows/2)+1), but I couldn't get it to populate the new tables. I'm not doing it right. Still working on it.
Sign In or Register to comment.