Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
I wrote some code and included the 'random = arc4random() % 50;'. All the code worked but when I finished I noticed that I did not include #import <stdlib.h> but the code still worked. How can that be?

Here is the code
Code:
#import <Foundation/Foundation.h>


@interface randNum : NSObject 
{
	int random;
}
@property int random;
-(void) print;
-(void) guess;

@end
Code:
#import "randNum.h"

@implementation randNum
@synthesize random;

-(void) print
{
	NSLog(@"The random number is %i", random);
}
-(void) guess
{
	random = arc4random() % 50;
}
@end
Code:
#import "randNum.h"

int entered;

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	randNum * guesser = [[randNum alloc] init];


	guesser.guess;
	entered = guesser.random;
	guesser.print;

	NSLog(@"-----> %i",entered);
	guesser.release;

    [pool drain];
    return 0;
}
 
I see. Because if it was not it could not work I guess.

Is there a list some place that shows you what is in the different classes?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.