Skip to content

Instantly share code, notes, and snippets.

@irace
Created April 21, 2015 17:55
Show Gist options
  • Save irace/86067704c334c9ff277c to your computer and use it in GitHub Desktop.
Save irace/86067704c334c9ff277c to your computer and use it in GitHub Desktop.
Randomly pick a deserving team member to give your WWDC ticket too. Allows for weighting in case you like some more than others.
#!/usr/bin/env xcrun swift
import Foundation
struct Teammate {
let name: String
let weighting: Int
}
let teammates = [
Teammate(name: "Foo", weighting: 3),
Teammate(name: "Bar", weighting: 2),
Teammate(name: "Baz", weighting: 3)
]
let entries = teammates.flatMap {
[String](count: $0.weighting, repeatedValue: $0.name)
}
let winner = entries[Int(arc4random_uniform(UInt32(entries.count)))]
println(winner)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment