generate a random number between 1 and 10 in swift

You can use the arc4random_uniform(_:) function to generate a random number within a range in Swift. To generate a random number between 1 and 10, you can use the following code:

main.swift
let randomNum = arc4random_uniform(10) + 1
43 chars
2 lines

This will generate a random number between 0 and 9 using arc4random_uniform(_:), and then add 1 to it to shift the range to 1 to 10.

gistlibby LogSnag