我尝试使用下面的代码来生成随机负NSInteger的,生成一个随机的负NSInteger的
+ (NSInteger)getNegativeRandomNumber {
uint32_t random = arc4random_uniform(2147483647); // where 2147483647 is the max 32-bit positive value returned by random function
return (NSInteger)(-1 * random); // convert the positive into negative number
}
但有时这些代码让我的正数。你看到这个代码的任何问题?
'回报 - (NSInteger的)随机的;'。这个问题是由于64位和32位体系结构,而'NSInteger'具有不同的定义。你正在做' - 'sutff,随机和铸造。 – Larme