Display random number from a table

MelodyCatsMelodyCats Member, PRO Posts: 128

So I have a Table of 12 rows with numbers (called TB Numbers) and I want to randomly display one of the numbers.
so far so good but here's the things - I only want it to randomly display the numbers that are greater than 0.
Is there a way to make it ignore any zeros in my column.
I thought it would be relatively straight forward but I'm seriously struggling with it.
I'm attaching an example. (right now if you refresh it will pick a random number but will display zeros too)
Many thanks for any suggestions!

Comments

  • MelodyCatsMelodyCats Member, PRO Posts: 128

    OK so a couple of hours later I may have a solution - adding an extra game attribute and using a loop. Not sure if this is the most elegant solution but attaching an updated example in case any one else is trying to do something similar.

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @MusicBoutique

    Quite a simple and neat solution, I like it.

  • ArmellineArmelline Member, PRO Posts: 5,420
    edited December 2016

    Edit: Your solution is probably easier, though :D

    Do the rows with 0s often change? I'd be tempted to make a text attribute, and populate it with the rows of the table that have 0s. i.e.

    01,05,09,11,21,24,29,34,46,78,

    Then rather than picking a random table row, you pick randomly from that attribute. random(1,textLength(attribute)/3)

    Then you know which row you're after by using something like textSubStr(attribute,random3-2,random3-1)

    Add new rows by appending the string with the row number (using padInt) and the comma. i.e.

    Change attribute random_pool to random_pool..padInt(random,2)..","

    Remove them by doing textReplace.

    If that makes any sense :D

  • MelodyCatsMelodyCats Member, PRO Posts: 128
    edited December 2016

    Thanks @Hopscotch !
    Thanks @Armelline - That looks like an interesting idea to explore too.

Sign In or Register to comment.