KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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?
Tags (comma-separated)
Save Edits
Cancel