Random rows and columns in tables

Good morning, all:

I am trying to choose random row in a table and then a random column associated with that row and then print that row/column combination.

The following code below does not compile, I am just including it as an example of how I have tried to approach the problem. Actually, the first three lines compile just fine. Anyway, what I have is:

carry out singing:
	choose a random row in the Table of Radio Songs;
	let N be the title entry;
	say "[N]";
	choose a random column in the table of radio songs;
	say "[random column in the table of radio songs]";

I also tried:

carry out singing:
	choose a random row in the Table of Radio Songs;
	let N be the title entry;
	say "[N]";
	choose a random column entry of N;
	say "[column entry]";

I can’t figure out how to choose the column associated with the row.

As always, your help is greatly appreciated. My
CREDITS list is consistenly growing…

Thank you!

Unfortunately, there’s no way to choose a random column. Columns can have different types, and expressions in I7 always have to have one specific type.

As a workaround, you can put a list in a table column, and choose a random entry from that.

1 Like

That’s weird but I suppose it makes some sense looked at through that lens. Thanks, as always, Draconis!

You can also say something like

choose a random row in the foo table;
if a random number from 1 to 5 is:
  -- 1: decide on the col1 entry;
  -- 2: decide on the col2 entry;
  -- 3: decide on the col3 entry;
  -- 4: decide on the col4 entry;
  -- 5: decide on the col5 entry;

As long as all five named columns have the same type, this will work.

(Code not tested; syntax may not be quite right.)

Thank you, I thought about this but wasn’t sure how to code it.

Thank you, Zarf!

Actually, if you just want to print out the randomly-chosen cell, this is technically possible.

Yes, that’s what I’m interested in!

It’s kind of involved. In all honesty, you’re probably better off re-configuring the data structure of your table. Can you describe it (or something analogous to it) here?