[I7] random rows in table

I was trying to pick a random row in a table that adheres to certain conditions. In other words, possibly use a table as a database.

So I was wondering if I was missing a shortcut. I was able to do what I wanted, but the code doesn’t seem elegant. The code below works–basically, I want to choose a random row with bb=1.

I have some simpler syntactical tries below, and they seem like they should work, but they all failed me. What am I missing, if anything? I’m quite possibly a bit spoiled by the natural language Inform does understand, here…

[code]“randomrow” by Andrew Schultz

table of randrow
aa bb cc
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

room 1 is a room.

when play begins:
let LL be a list of numbers;
repeat with Q running from 1 to number of rows in table of randrow:
choose row Q in table of randrow;
if bb entry is 1:
add Q to LL;
let T2 be number of entries in LL;
let Q2 be a random number from 1 to T2;
let Q3 be entry Q2 of LL;
choose row Q3 in table of randrow;
say “[Q3] [aa entry] [bb entry] [cc entry].”;

[definition: a row (called wor) is super-awesome:
if bb entry is 1:
decide yes;
decide no;

when play begins: [neither of these work at least as coded]
choose a random row with bb of 1 in table of randrow;
choose a random super-awesome row in the table of randrow;
say “[aa entry] [bb entry] [cc entry].”;][/code]

Thanks!

No, I don’t think there’s a more concise way to do this.

“Table rows” aren’t a type, so you can’t define descriptions using them or definitions on them.

You could define “a number is super-awesome” based on the properties of that numbered row, but you couldn’t go on to select “a random super-awesome number”.

Sometimes you can sort a table in-place, so that the N rows of interest are at the top, and then select a random number from 1 to N.

Thanks! Those ideas opened up some cool solutions I hadn’t thought of. I didn’t know whether table rows were a type, so I appreciate the confirmation.