If amount of "itemx" keep changing, then you need to remember to update that helptable as well. Good thing however is that if you are looking for random value among all the "item"s, then you dont need to worry that table and helptable have them in same order, as it doesnt really matter which "itemx" it happens to pick as long as it is random and exists. And do remember, if you remove one "itemx" from your table, you need to remove that from helptable as well, or you might be trying to access non existing table item.

Thanks for the idea.That table is changing - it is getting smaller and smaller until it becomes null.

I asked that question because I'm trying to speed up my program as much as possible on classic amiga (that "get random" routine is used in main loop of the script).I am going to try your solution and will report if that speeds up things

Now each call to the function will pick a value using a random value among the existing indexes (which implicitly goes between 0 and the number of items-1). Then remove that item with RemoveItem() and you will have a 'rebuilt' and reduced table since Hollywood automatically handles the indexing with implicitly assigned indexes.

Of course you will eventually run out of items in the list as you remove them. So you have to be able to handle this condition in your code.

I don't think there's a faster way than your original code based on iterating the table until you reach the random index. There's no way to go from an absolute, consecutive index to a non-consecutive index without iterating through the table.

The procedure I suggest will work provided the value you are interested in is the content (which might be a number or a string) and not its index in an table. As I understand your task, you have a list of valuesand wish to grab a random item in the list for some purpose, then reduce the list by removing that item, then later grab another random item, then reduce the list by removing that item... etc.

In other words, in your situation the actual value of the index in the table is not important, which is why you can use the implicit indexing (consecutive indexes). Because it is only used to do random picking among the items. If however you actually use the index value as a parameter in some other context, then my idea is not useful.