Randomize members list order in for loops

xtend
rules
groupitems
Tags: #<Tag:0x00007f51de0cf288> #<Tag:0x00007f51de0cf148> #<Tag:0x00007f51de0cf008>

(Peter) #1

When using for loops for away ghost modes, or party random lights most of the samples does not randomize the order of light switching.

A simple and quick way of randomizing the order of members in a group for use in a for loop is to replace the sortBy function with a random function.

B_All_Lights.members.sortBy[g|(Math::floor(Math::random*100))].forEach(light,i |
          logInfo("Vacation","Hello Light" + light)
      )

The above function will output the members of the B_All_Lights in a random order when called.