This seems to be a really strange issue:
This is my code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
srand((unsigned int)time(NULL));
int newRandomNumber = 0;
newRandomNumber = rand() % 7;
NSLog(@"%d", rand() % 7); //This prints out what I expected
NSLog(@"newRandomNumber = %d", newRandomNumber); // This always prints out 0!
}
return 0;
}
If I replace that one line that says
newRandomNumber = rand() % 7
with
newRandomNumber = rand() % 8
everything works perfectly. Why is that the case?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…