In case this helps anyone else, I had a few scenarios where I really want things to happen in a random order (a good QA strategy, rather than always being the same).
There doesn’t seem to be a built-in way, so here’s what I came up with. Just pass a comma delimited list and you’ll get it returned in a different order.
scriptname : orderListByRandom
params vList
/// should be a comma separated list .
set vListCount to the number of items in vList
set rOrderList to any item of vList & "," // need to start the new random Order list so we can validate against it.
repeat while the number of items in rOrderList is less than vListCount
set newItem to any item of vList
set uniqueItem to "" // reset it (always a good idea when we're looping)
repeat with each item in rOrderList
if newItem = it
set uniqueItem to false
exit repeat // we don't need further evaluation since it matched.
else
set uniqueitem to true
end if
end repeat
if uniqueItem = true
put newItem & "," after rOrderList
//put "Items in random list: " && the number of items in rOrderList //debug
end if
end repeat
if the last character in rOrderList is "," // trim it.
delete the last character in rOrderList
end if
//put rOrderList // debug
return rOrderList
use this to see that it does order a list at random:
put (1,2,3,4,5) into mylist
repeat 5 times
put orderListByRandom(mylist)
end repeat
Your output will list 5 different orders of the items (numbers) passed. Hope this helps someone.