I’ve got a group with 16 items in it. See below.
I now want to select randomly several items, switch them ON, switch them OFF and and switch ON other randomly items.
Any idea/suggestion how I can do this?
For example:
Select 3 random things from GroupA: SelectionItems = Relay04 - Relay09 - Relay11
Set ON: sendcommand( SelectionItems, ON)
Sleep 10 second: createTimer(now.plusSeconds(10))
Set OFF: sendcommand( SelectionItems, OFF)
Select 3 (or 4 if possible?) other things from GroupA: SelectionItems = Relay05 - Relay14 - Relay03 - Relay06
Just a few ideas out of my head, you have to look for the correct syntax:
put all items into a Map(java.util.Map) with the label as key
use Math.random() * 16 as IntegerValue to select a random item - something like ‚myMap.get(„Relay „ + IntegerValue(Math.random() * 16)).sendCommand(ON)‘
Found these already. But for me, these are more ‘random times’?
I’m trying to figure out how I can get random items (more then 1!) from a group…
Sorry if I don’t see the solution in these topics. I’ve got just a limited knowledge of scripting. So most is try and error.
ps In the end, it’s an exercise for a group of outside Christmas lights (16 different lights), that will ‘never’ use the same pattern. Minute 1 those lights, minute 2 other lights, minute 3 again other lights…
Okay, we only know what you tell us about what you have already tried.
The first link provided selects a random member of a group.
Doing that again will give you another one.
Probably more useful -
The last link gives a randomized list of group members. You may then use that to choose a random number of members from the head of the list.
I was trying to add [0:5] in the ‘members’ rule, but this doesn’t same to work.
And it seems that this rule won’t be put in a var? Guess because it’s list, and not only 1 value?
Will have another try later on. Getting a bit dizzy, to much screen today.