RunActions(
// Loop through the People table, working on each row one at a time
People.FormulaMap(
RunActions(
// Generate a random number for the random number column
ModifyRows(
CurrentValue, // CurrentValue means the current Person in the People table
[Random Number],
// For the seed, we're using the last modified date of the row, so that
// we get a fresh result each time we press the button; and also the ID
// of the row, so that we get a unique result for each row
Randomizer::RandomFromSeed(
CurrentValue.[Last Modified].ToNumber() + CurrentValue.RowId()
)
),
// Clear out any old matchups from last time we pressed the button
ModifyRows(
CurrentValue,
Matchup,
""
)
)
),
// Now that there are random numbers there, loop through the table in random order
WithName(
People.Sort(true, People.[Random Number]),
SortedPeople, // Every time we say SortedPeople, we mean the randomly-sorted table
// This is a "for loop"
Sequence(1,SortedPeople.Count()).FormulaMap(
// We're pulling names from the hat in pairs; so on odd pulls (e.g. 1st or
// 5th pull), we'll pair them with the next pull (2nd or 6th). That means on
// even pulls (2nd or 6th), we'll pair them with the previous pull (1st or 5th)
If(
// CurrentValue is the number of times we've been through this loop (our pull#)
CurrentValue.IsEven(),
ModifyRows(
// E.g. on our 6th pull, edit the row for the 6th Person
SortedPeople.Nth(CurrentValue),
// Edit its Matchup column
Matchup,
// Set that Matchup column to the 5th Person (6 - 1)
SortedPeople.Nth(CurrentValue-1)
),
ModifyRows(
SortedPeople.Nth(CurrentValue),
Matchup,
SortedPeople.Nth(CurrentValue+1)
)
)
)
)
)