[request] want to select randomly from a list of matches (e.g. findAll())

Bug #1275728 reported by obiwan-92
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SikuliX
In Progress
Medium
RaiMan

Bug Description

*** workaround on the Python level (SikuliX script):
import random
click(random.choice(list(<some_region>.findAll(<some-image-or-pattern>)))))

----------------------------------------------------------

I need sikuli to choose randomly from its image recognition findings, how is that possible?

My code in this case is:

 exists("autoSpectate.png",9999) # Wait for Spectate
 click("autoSpectate-1.png") # Click on Spectate

There are normally a few "Spectate"s, but it mostly clicks on the same one.

 Is there a possiblility to make it randomized intentionally?

Thanks!
---------------------------------------------------------------
Seem to be a good idea to develop.
Look at the question to find the actual workaround.

RaiMan (raimund-hocke)
summary: - [request] Add a function to select randomly in Sikuli
+ [request] want to select randomly from a list of matches (e.g.
+ findAll())
Changed in sikuli:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.2.0
description: updated
RaiMan (raimund-hocke)
description: updated
description: updated
Revision history for this message
Raffles (robert-finking) wrote :

I would suggest that Sikuli doesn't need to re-invent the wheel here, python already has a lot of ways of shuffling a list. E.g if you have:

    matches=findAll(pat)

Adding just one line (plus an import) will give you what you want:

    from random import shuffle

    matches=findAll(pat)
    shuffle(matches)

Simples :-)

RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 2.0.0 → 2.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.