如何使用applescript创建非重复的随机数

时间:2013-05-18 19:13:04

标签: applescript

试图弄清楚如何使用applescript创建非重复数字。如果我只想要1或2的随机数,我希望我的结果是[1,2]或[2,1],而不是[1,1]或[2,1]。

所以我基本上需要找出一种方法可以确保数字不重复,其他一切我知道怎么做。如果有一个unix命令我可以用applescript运行,请告诉我。

1 个答案:

答案 0 :(得分:2)

下一个AppleScript将生成非重复的随机数对 - 范围为1..100

set maxValue to 100
set thePairs to {}
repeat until (count thePairs) = 2
   set randomNumber to (random number from 1 to maxValue)
   if thePairs does not contain {randomNumber} then set end of thePairs to randomNumber
end repeat
thePairs

我希望你不会再将问题修改为其他问题。

相关问题