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