Avatar ·

How to generate a random number in Swift? (Int, Double, Float, Bool)

Hello everyone! I'm a beginner iOS developer writing my first app in Swift. I've run into a problem: I need to generate a random number, but I don't understand how to do it correctly in modern Swift. In older tutorials, I've seen the use of `arc4random()`, `arc4random_uniform()`, and even `rand()`, but Xcode complains about these functions, saying they are deprecated or don't work at all in some contexts. For example, I tried doing this: ```swift let randomNumber = arc4random_uniform(10) print(randomNumber) ``` This compiles, but returns `UInt32`, while I need `Int`. When I try to use this in calculations, I have to do type casting, which is inconvenient. And if I need to generate a random floating-point number, for example a Double from 0.0 to 1.0, I'm co