AppleScript返回随机浮点 [英] AppleScript return on random float
问题描述
我试图在AppleScript中创建代码,每1-2秒钟随机点击我的鼠标...我想要一个我玩的视频游戏不知道或能够告诉一个机器人为我点击所以我需要它是RANDOM ...不是每秒或每2秒,但每x秒,其中x是一个不断变化的变量,在1和2秒之间...这里的代码到目前为止,但它点击每1秒:
I'm trying to create code in AppleScript that will click my mouse randomly every 1-2 seconds... I want a video game I'm playing to not know or be able to tell that a robot is clicking for me so I need it to be RANDOM... not every second or every 2 seconds but every x seconds where x is a constantly changing variable in-between 1 and 2 seconds... Here is the code so far but it clicks every 1 second:
on idle
tell application "System Events"
key code 87
end tell
return 1
end idle
我想改变 return 1 到
返回随机数1到2
会工作
:
on idle
tell application "System Events"
key code 87
end tell
set randomDelay to random number from 1 to 2
return randomDelay
end idle
$ b b
但不起作用:
but it didn't work /:
推荐答案
使其成为
random number from 1.0 to 2.0
你给整数作为随机数的边界,它将只选择随机整数。通过给出浮点文本,AppleScript切换到给出范围内的随机浮点数。从StandardAdditions中的随机数
的文档中,看起来这些限制都是包含的,这对于浮动来说很奇怪,但在你的情况下不是问题。
If you give integers as the bounds for the random numbers, it will just select random integers. By giving floating point literals, AppleScript switches to giving a random floating point number in the range. From the documentation of random number
in the StandardAdditions, it seems that the limits are both inclusive, which is strange for floats but isn't a problem in your case.
这篇关于AppleScript返回随机浮点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!