2

AppleScript を使用して非反復番号を作成する方法を見つけようとしています。乱数を 1 または 2 だけにしたい場合は、結果を [1, 2] または [2, 1] にして、[1, 1] または [2, 1] にしないでください。

したがって、基本的には、数字が繰り返されないようにする方法を理解する必要があり、それ以外の方法はすべて知っています。AppleScript で実行できる UNIX コマンドがあれば教えてください。

4

1 に答える 1

1

次の 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

質問を別のものに再度変更しないことを願っています。

于 2013-05-18T20:22:21.697 に答える