Created
April 18, 2018 16:38
-
-
Save spig/7eb905ffa17f35019d63e144654e0613 to your computer and use it in GitHub Desktop.
Random Length Substrings
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
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