Sikuli RNG script repeating the same number

3323 views python
0

When I use the type(str(num)) for random numbers I get the same one over and over: 510304296165725

I'm not sure why it keeps repeating since the parameters are set before the script starts to loop. I can't get the code to fit right, but it is indented properly.

running = True
def runHotkey(event):
    global running
    running = False
import random
num = random.randrange(000000000000000,999999999999999)
Env.addHotkey(Key.F1, KeyModifier.CTRL, runHotkey)

while exists(Pattern("1495843225731.png").similar(0.10)) and running:


    if exists(Pattern("1541289046943.png").similar(0.71)):
  DoubleClick(Pattern("1541289689152.png").similar(0.90).targetOffset(-39,3))
        wait(1)
        type(str(num))        
        type(Key.ENTER)
        wait(1)

else:
    wait(1)
    click(Pattern("1541289841740.png").similar(0.82))
    wait(1)
    type("1.wav")
    type(Key.ENTER)

answered question

You start by running = False so how is your code entering the while loop?

1 Answer

9

Figured it out!! The script would identify a random number to use for the given loop before it ran. I placed the import random number at the start of the loop and it generates a new one each time. Thanks for the help.. here it is:

running = True
def runHotkey(event):
    global running
    running = False
Env.addHotkey(Key.F1, KeyModifier.CTRL, runHotkey)

while exists(Pattern("1495843225731.png").similar(0.10)) and running:
    import random
    num = random.randrange(000000000000000,999999999999999)



if exists(Pattern("1541289046943.png").similar(0.71)):
    doubleClick(Pattern("1541289689152.png").similar(0.90).targetOffset(-39,3))
    wait(1)
    type(str(num))        
    type(Key.ENTER)
    wait(1)

else:
    wait(1)
    click(Pattern("1541289841740.png").similar(0.82))
    wait(1)
    type("1.wav")
    type(Key.ENTER)

posted this

Have an answer?

JD

Please login first before posting an answer.