Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created April 23, 2019 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfix/fc765c34e36df5b91b9d7bea6c18af6e to your computer and use it in GitHub Desktop.
Save rayfix/fc765c34e36df5b91b9d7bea6c18af6e to your computer and use it in GitHub Desktop.
struct Dice: Codable {
var range: Range<Int>
init<R: RangeExpression>(range expr: R) where R.Bound == Int {
range = expr.relative(to: Range<Int>(Int.min...Int.max-1))
}
func roll() -> Int {
return Int.random(in: range)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment