I have this expression which returns a UInt32
:
let randomLetterNumber = arc4random()%26
I want to be able to use the number in
Just create a new int with it
let newRandom: Int = Int(randomLetterNumber)
if letters.count > newRandom {
var randomLetter = letters[newRandom]
}
or if you never care about the UInt32 you can just create an Int immediately:
let randomLetterNumber = Int(arc4random() % 26)
More simple than this, impossible:
Int(myUInteger)
Int(arc4random_uniform(26))
does two things, one it eliminates the negative results from your current method and second should correctly creat an Int from the result.
You can do
let u: UInt32 = 0x1234abcd
let s: Int32 = Int32(bitPattern: u)