I7 : lists or table

Hi all,

I’m kind of curious, in that I have a design decision to make, and I wanted to be sure that I’m not choosing the least optimal construct. Typically, you would use [one of]…[or]…[at random] for varying some text:

say "The cat is [one of]hairy[or]bald[or]furry[or]scruffy[at random].";

but for re-use purposes, I might want to hold these text values as a list, or a table. I guess my question is, is there a ‘better’ way of doing it. I can select a row in a table at random, and I can select an element in a list at random, but this is more of a pain in the ass.

For a table :

[code]Table of AnimalTypes

choose a random row in table of AnimalTypes;
say “The cat is [type entry].”;[/code]

For a list:

[code]AnimalTypes is a list of text that varies. AnimalTypes is {“hairy”,“bald”,“furry”,“scruffy”};

Let N be the number of entries in AnimalTypes;
Let R be a random number between 1 and N;
say “The cat is [entry N of AnimalTypes].”;[/code]


sort AnimalTypes in random order; say "The cat is [entry 1 of AnimalTypes];

Is one of these preferable from a back-end perspective, or are they computationally equivalent? Do tables have a higher overhead than lists? For very large lists, the sorting in random order seems to be quite expensive. However, for tables, I am constantly having to revise the MAX_STATIC_DATA setting. Also, am I missing a ‘select random entry from list’ syntax? I can’t seem to find it in the documentation.



try using sticky random. It sticks the term “hairy” into the first play, which means on a second play it might be “bald” so it adds replay ability.

Read §5.7. Text with random alternatives in the Manual on how to do it.

In the Inform 7 extensions public library, there’s one called List Control by Eric Eve which combines tables with shuffling, cyclic or stopping behaviour. Don’t be thrown by the word ‘list’ - technically, it uses tables all the way.

In terms of computation, there’s no problem raising MAX_STATIC_DATA as often as is required. It’s more common to be worried about which method will execute slower, especially if you run the game online where such effects can be more pronounced. Offline they’re often invisible, unless you’re dealing with massive amounts of data.

I don’t think the benchmarking extensions work with the current Inform. I just know bits and pieces from anecdotes and from recent experiments of my own. My own test showed writing data to a huge list was considerably slower than doing so in a table with the same number of entries. I should have written this stuff down… you know, I did 100 and 1000 and maybe 10,000. Somwehere between 100 as we moved up towards 10,000, the list time overtook the table time very significantly. But that’s just building the list.

Someone else here recently showed that looking things up in tables, especially if items were near the end, was surprisingly taxing. But that may have only been a surprise relative to what was expected : )

My advice is that if you can’t detect a speed change offline, use whichever method you find most convenient. But what I’d do is build your game to a website and try it there (‘release along with an interpreter’). That wilI exaggerate the speed hits of various processes. Doing this showed me my extension couldn’t be run online without a 3 second interval between some turns, which motivated me to optimise and replace bits, and I got it down to a fraction of a second per turn online.


Wade - perfect. That’s exactly what I was looking for. Thank you.

If you open the Javascript error console (command varies per browser) you will see the exact time taken by each command, in milliseconds.