Most efficient way to select a random table row where column is true?

goonergooner Lancaster, PAMember Posts: 135
edited September 2015 in Working with GS (Mac)

I would like to select a random row where the column "isActive" has a value of true. I currently have about 10 rows with 3 of them having "isActive" set to true. The further along in the game you get, more of the rows will be set to true, making more of them available to be selected.

I am currently attempting this by having a duplicate table that gets populated by checking each row in the master table. If "isActive" is set to true in the master table then I want to insert this row into the duplicate table. When all rows have been inserted into the duplicate table, I can select a random row with something like random(1, tablerowcount(tableDuplicate)).

Is this too convoluted and is there a simpler way? Use attributes instead of table? Any advice is well appreciated.

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited September 2015

    Hi @ellison, your approach sounds fine.

    @ellison said:
    ... gets populated by checking each row in the master table.

    I am just curious about the above. It sounds like you are cycling through the table periodically? If you are, rather just add the appropriate row to the duplicate table as and when a row becomes "active".

  • goonergooner Lancaster, PAMember Posts: 135

    @Hopscotch said:
    I am just curious about the above. It sounds like you are cycling through the table periodically? If you are, rather just add the appropriate row to the duplicate table as and when a row becomes "active".

    Yes, I figured I would check the tables at the start of each level to keep them in sync, but I guess that does sound like overkill.

    Thanks for the suggestion, I will try that.

Sign In or Register to comment.