def allPlayers = []
def player
def teamSize
def badInput = true

Scanner sysin = new Scanner(System.in)
def rand = new Random(System.currentTimeMillis())

while(badInput) {
    print "Enter team size: "
    teamSize = sysin.nextLine()
    badInput = !teamSize.isInteger()
}

teamSize = teamSize.toInteger()

// theoretically no point, but seems to make it more random
// we're choosing pickup teams, so appearence matters :)
(1.10000).each {rand.nextInt() }

while(true) {

    print "Name: "
    player = sysin.nextLine()

    if (player == null || player == "DONE")
        break
    
    allPlayers << player

}

allPlayers.sort({ return rand.nextInt() })

println "\nTeam Assignments:"
println "-------------------"

def teamNum = 0
for (int i = 0; i < allPlayers.size(); i++) {
    if (i % teamSize == 0)
        println "\nTeam ${++teamNum}"

    println "    ${allPlayers[i]}"
}
