I'm trying to get a random name from this Array as a string instead of a number.
I.E: The array normally returns a random number 0 through 9, I'd rather have it return the string that 0 through 9 represents like Preston or James instead of the number itself.
The code below is broken, but I hope it lets you see what I'm trying to do.
var firstName : [String] = ["Preston", "Ally", "James", "Justin", "Dave", "Bacon", "Bossy", "Edward", "Edweird" ]
var standardIdent = "First Name:\(firstName[random(0...9)]) Last Name:\(lastName[random(0...5)]) \n Age:\(rand())"
println(standardIdent)
Thank you for your help!
You should use arc4random
like:
let firstRandom = Int(arc4random() % 10)
let secondRandom = Int(arc4random() % 6)
var standardIdent = "First Name:\(firstName[firstRandom]) Last Name:\(lastName[secondRandom]) \n Age:\(rand())"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments