I stumbled upon the fact that when a random number is generated in Swift, it is of type UInt32
by default instead of type Int
What's the reason?
I suspect you are referring to arc4random
. This function returns UInt32
because the underlying C function (also called arc4random
) returns uint32_t
, which is the C equivalent of Swift's UInt32
.
I would assume it makes it faster. If you want Int random numbers take a look at GKRandomSource in the game kit, https://developer.apple.com/documentation/gameplaykit/gkrandomsource