With the iPhone 5S update, I want my app to support the new 64-bit processor.
However, the use of 64-bit code can lead to truncation if a larger data type is placed into a smaller one, as in the case of casting a long one in int. Most of the time, this can be easily fixed by simply using a larger data type, but in the case of random number generators that are sometimes sown using the "time (NULL)" function, I cannot do this.
The current code is simple:
srandom(time(NULL));
But in XCode 5 with a 64-bit result of the following error: Implicit conversion loses integer precision: 'time_t' (aka 'long') to 'unsigned int'
. This is because "time (NULL)" returns a long integer, and "srandom" requires an unsigned int. Therefore, there are two options:
- Convert long integer to unsigned int
- Replace "time (NULL)" with another function that performs the same task, but returns an unsigned int.
Which one would you recommend and which function should I use for this?
NOTE. I use random () instead of arc4random (), because I also need to be able to generate a random number generator in order to get a repeatable result.
source share