Search code examples
google-sheetsgoogle-sheets-formula

Generate a random tennis match using two groups of players in google docs


I need some help with the formulas for a google sheet I'm putting together. In the attached image you can see that I have two groups of players - with 8 players in each group.

I would like to generate or create a match using those 16 players but:

  • players from group A can only play with a different player from group A (i.e., not themselves). Same for group B
  • The pair from group A plays against the pair from group B. This produces 4 games using all of the players.

In the attached image you can see an example of what I'm looking for in B12:E15.

I'm having issues with the formulas to prevent duplication. I'm using formulas like =INDEX(A2:A9, RANDBETWEEN(1, 8)) to randomize the player and then a formula such as =INDEX(FILTER(A2:A9, .....) with conditions but I keep getting circular references.

enter image description here


Solution

  • Here's one approach you may test out. the formula is linked to the checkbox in Cell_B10 so as to bypass the constant randomization of the output that'll happen due to any edit(s) happening in the sheet. now it exclusively happens on checkbox toggle

    =wraprows(sort(A2:A9,let(Σ,lambda(x,x)(randarray(8)),if(B10,Σ,Σ)),),2)
    

    enter image description here