multiple some items?

I’m trying to select two random items from a list. My work around right now is to “get some item” in a 2x repeat loop. That was working until I realized that it could pick the same item twice. I’m looking into removing the selected item from the list before it loops around, but this seems very cumbersome. I would think it would be a lot simpler if I could just say

set {firstItem, secondItem} to {some item, some item}

Make sense? Can “some item” work this way?


you could check the second item whether it’s equal to the first one

set randomList to {}
repeat 10 times
	set end of randomList to random number from 1 to 20
end repeat

set a to some item of randomList
	set b to some item of randomList
	if b is not a then exit repeat
end repeat

I like this approach:

set tList to {"A", "B", "C", "D", "E"}
set tPair to {}
repeat until (count tPair) = 2
	tell some item of tList to if it is not in tPair then set end of tPair to it
end repeat

Cool! Thanks guys. I’ve already incorporated Stefan’s approach, and that works fine as long as I know in advance how many items I want to pull from the list. At first glance it looks like with Adam’s I can set the “repeat until” count to a user designated variable, which is even better.

As an aside, it is considered good practice to post a final script somewhere? I’ve asked a few questions in the past week all for the same script I’ve been working on; didn’t know if people like to see what they’re actually helping with.