猴子跑步者随机生成

时间:2012-01-17 13:25:34

标签: android scripting random jython monkeyrunner

当我想输入一些字符时,我会这样做

device.press("0",MonkeyDevice.DOWN_AND_UP)

这使得char'0'输入,并且效果很好

但问题是我想输入0到9之间的随机数,比方说1000次

我该怎么做?我怎样才能在monkeyrunner中随机生成

我想随机选择:

device.press("0",MonkeyDevice.DOWN_AND_UP)
device.press("1",MonkeyDevice.DOWN_AND_UP)
device.press("2",MonkeyDevice.DOWN_AND_UP)
device.press("3",MonkeyDevice.DOWN_AND_UP)
...
device.press("9",MonkeyDevice.DOWN_AND_UP)

修改

我想这样做

device.press("Random Number between zero and nine",MonkeyDevice.DOWN_AND_UP)
device.press("Random Number between zero and nine",MonkeyDevice.DOWN_AND_UP)
device.press("Random Number between zero and nine",MonkeyDevice.DOWN_AND_UP)
device.press("Random Number between zero and nine",MonkeyDevice.DOWN_AND_UP)

...

但我需要有效的语法才能做到这一点

2 个答案:

答案 0 :(得分:0)

我并不完全确定你要做的是什么,但是如果你想要的是 -

device.press("Numberbetweenzeroandnine",MonkeyDevice.DOWN_AND_UP)

然后我建议生成一个0到9之间的随机数到一个整数,并传入这个整数。

答案 1 :(得分:0)

因为monkeyrunner在Jython API上运行,请尝试使用str(random.randint(0, 9))代替"Random Number between zero and nine"