How to choose randomly from several lists and use them?

Asked by alceal

Hello again.

Step by step I'm writing new scripts for new situations that sikuli could help me a lot. I'm not a programmer. I'm an autodidact but although I have found answers for other problems, this one is resulting very complicated for me.

I've got two lists:

App1 = whatever1.png
App2 = whatever2.png
App3 = whatever3.png

listApps = [App1, App2, App3]
listOptions = [Option1, Option2, Option3]

Sikuli must choose one from each list randomly and does:

click(AppX)

paste('running AppX: Please, choose OptionX')

Any help?

P.D: Sorry, I'm not an english native.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
alceal
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

import random

click(random.choice(listApps))

paste('running AppX: Please, choose" + random.choice(listOptions))

... supposing listOptions contains strings

Revision history for this message
alceal (alceal) said :
#2

Thanks, Rai. You're alright. listOptions has strings.

One question: in paste('running AppX: Please, choose" + random.choice(listOptions)), AppX is chosed randomly too. So it must paste that AppX too. e.g. running App1: Please, choose...; running App2: Please choose...; etc.

Other question: if I want non exactly random choice. I mean: On one hand: App1 60%, App2 30% and App3 10% and the other hand Option1 50%, Option2 25% and Option3 25%.

I tried this one succesfully:

import random

rNum = random.random()

if rNum < float(6)/10:
    click(ima1,png)
elif rNum > float(6)/10 and rNum < float(9)/10
   click(img2.png)
else:
   click(img3.png)

How could I use it in my problem?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

ok, you can do the same, but evaluate an index this way:

only using your example, has to be adapted as needed:

rNum = random.random()

if rNum < float(6)/10:
    ixa = 0
elif rNum > float(6)/10 and rNum < float(9)/10
  ixa = 1
else:
   ixa = 2

# same for ixo (listOptions)

click(listApps[ix])
paste('running App%d: Please, choose %s" %(ixa, listOptions[ixo)))

Revision history for this message
alceal (alceal) said :
#4

Thank you very much for your help.