Pick a number that's not (this one).

Hiya!

I want to do something secret that is completely dependent on choosing TWO things from the same list of possibilities, while making sure the SECOND pick is NOT the FIRST.
And I’m not yelling, it’s just that I7 is laughing at me.

Anyone know of a good way to do this? Plz?

How do you have the list represented? If it’s a range of numbers you could do something like this:

Let first number be a random number between 1 and 10; let second number be a random number between 1 and 10; while second number is first number: [tab]now second number is a random number between 1 and 10;

Of course you need to make sure the range has more than one thing in it to avoid an infinite loop.

will that work with this?

Table of stuff number output 1 "Ding" 2 "Dong" 3 "The" 4 "Witch" 5 "Is" 6 "Dead"

Yeah, you’d just have to add something like this:

now first output is the output entry corresponding to a number of first number in the Table of Stuff; now second output is the output entry corresponding to a number of second number in the Table of Stuff.

There are lots of other ways to do it, too. If you’re only going to do this once, so it doesn’t matter whether the Table of Stuff gets defaced, you could do something like this:

choose a random row in the table of stuff; now the first output is the output entry; [note that this means "output entry in the row we've just chosen"] blank out the whole row; choose a random row in the table of stuff; now the second output is the output entry.

You’d have to make sure that you don’t wind up with a completely blank table before choosing a random row, though!

If the Table of Stuff is a little less defaceable you could do this:

Sort the Table of Stuff in random order; now first output is the output in row 1 of the Table of Stuff; now second output is the output in row 2 of the Table of Stuff.

This will shuffle the order of the Table of Stuff but will leave all the rows intact.

If the Table of Stuff needs to stay in the same order you could adapt the original solution:

choose a random row in the Table of Stuff; now the first output is the output entry; choose a random row in the Table of Stuff; now the second output is the output entry; while the second output is the first output: choose a random row in the Table of Stuff; now the second output is the output entry;

I’m not absolutely positive about this because checking whether two strings are the same can get wonky in Inform. Again, you need to make sure there are at least two rows or you’ll get an infinite loop.

In general there are lots of fun things you can do with tables–chapter 16 of the documentation is worth looking through. Also note that for most of these solutions I didn’t use the number column of the table. If you have a table you can choose random rows or look at row 1/row 2/etc. even if the table doesn’t have a column that’s labeled with a number, though the number could be useful if you’re using the random-sort method and you want to restore the original order, since you can just sort the table in number order.

Try using this instead.

while the second output exactly matches the text of the first output

It’s much better for comparing 2 strings.

Hope this helps.

Hm? No, “is” and “exactly matches” do the same thing in 6L38.

There was a bug in the vicinity of comparing text strings, though, wasn’t there? Was that fixed in 6L38?

The definition of string identity was harder to explain in earlier versions, and also there were bugs. It’s cleaned up now.

But “20.5. Matching and exactly matching” in The Inform Documentation says they are not the same. Documentation bug?

Can this be augmented to a phrase like this? now X is a random number between Y and Z that is not A or B or C; or something to that effect?

If you wanted to write “that is not A or B or C” you’d need a different phrase for “that is not A or B or C or D” or something like that. Tedious! But you can use a list:

[code]To decide what number is a random number between (x - a number) and (y - a number) but not in (LN - list of numbers):
let k be a random number between x and y;
while k is listed in LN:
let k be a random number between x and y;
decide on k.

When play begins:
repeat with k running from 1 to 100:
let N be a random number between 1 and 10 but not in {2, 3, 5};
say N.[/code]

This is pretty dangerous because if there are no valid numbers it will loop infinitely. If you want to make sure that won’t happen, you can write a phrase that compiles a list of numbers and removes your list from it, then selects a random element from the list… if you have a lot of numbers that might be inefficient, because lists can eat up a lot of memory (I think).