Created
April 21, 2015 17:55
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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