Load number in SWIFT

I am developing a fast iPhone application, and there is a requirement that I always generate negative random numbers.

I know how to generate random numbers Method, but it doesn’t seem to have come up with a method that only produces negative numbers.

please try This

let lowerValue = -100
let upperValue = 0
let result = Int(arc4random_uniform(UInt32(upperValue-lowerValue + 1) )) + lowerValue

print(result)

Output

-81

Me I am developing a fast iPhone application, and there is a requirement that I always have to generate negative random numbers.

I know how to generate random numbers, but I don’t seem to have come up with a Method to generate negative numbers.

Please try this

let lowerValue = -100< br />let upperValue = 0
let result = Int(arc4random_uniform(UInt32(upperValue-lowerValue + 1))) + lowerValue

print(result)

Output

-81

Leave a Comment

Your email address will not be published.