1

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?

Malik
  • 3,763
  • 1
  • 22
  • 35
Emma V.
  • 99
  • 1
  • 8

2 Answers2

3

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.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
1

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

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52