Imran Imran - 1 year ago 87
Swift Question

Swift- Generating random values between two Integer values

I'm trying to generate random values between two integers. I've tried this, which start from 0,

let randomNumber = arc4random_uniform(10)

But I need to print values between 10 to 50, Please suggest me....


Answer Source

try this

let randomNumber = arc4random_uniform(40) + 10

in general form

let lower : UInt32 = 10
let upper : UInt32 = 50
let randomNumber = arc4random_uniform(upper - lower) + lower
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download