0

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

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

这使得输入字符'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)

...

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

4

2 回答 2

0

So as monkeyrunner runs on Jython API, try using str(random.randint(0, 9)) in place of the "Random Number between zero and nine"

于 2012-03-07T16:37:45.493 回答
0

我不是 100% 完全确定你想要做什么,但如果你想要的是类似的东西 -

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

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

于 2012-01-17T13:28:56.027 回答