Skip to content

Instantly share code, notes, and snippets.

@danielctull
Created April 27, 2017 10:10
Show Gist options
  • Save danielctull/d1eba4c14fdfe18535247e1831e16746 to your computer and use it in GitHub Desktop.
Save danielctull/d1eba4c14fdfe18535247e1831e16746 to your computer and use it in GitHub Desktop.
A random generator for private building tiles in Great Western Trail.
import Foundation
extension String {
func pad(to length: Int) -> String {
guard self.characters.count < length else {
return self
}
let padded = "0" + self
return padded.pad(to: length)
}
}
let random = arc4random_uniform(1024)
let string = String(random, radix: 2, uppercase: true).pad(to: 10)
print(random)
for (index, character) in string.characters.enumerated() {
let value = Int(String(character))!
let side = value == 0 ? "A" : "B"
print(index+1, side)
}
@danielctull
Copy link
Author

danielctull commented Apr 27, 2017

Will print out the number of the combination, along with what the tiles should be, such as:

829
1 B
2 B
3 A
4 A
5 B
6 B
7 B
8 B
9 A
10 B

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment