Skip to content

Instantly share code, notes, and snippets.

@spig
Created April 18, 2018 16:38
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 spig/7eb905ffa17f35019d63e144654e0613 to your computer and use it in GitHub Desktop.
Save spig/7eb905ffa17f35019d63e144654e0613 to your computer and use it in GitHub Desktop.
Random Length Substrings
static let titleArray = "Youth Theme 2015: O YE THAT EMBARK IN THE SERVICE OF GOD".split(separator: " ")
static let artistArray = "Elijah Thomas, Kyle Thorn, Maddie Wilson, Grayson O'Very, Anna Richey, Nick Neel, Baily Lawson".split(separator: ",")
public func getRandomTitle() -> String {
return getRandomLengthString(from: type(of: self).titleArray, separator: " ")
}
public func getRandomArtist() -> String {
return getRandomLengthString(from: type(of: self).artistArray, separator: ",")
}
public func getRandomLengthString(from array: [String.SubSequence], separator: String) -> String {
return array[0..<Int(arc4random_uniform(UInt32(array.count)))].joined(separator: separator)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment