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.swift43 chars2 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