random = arc4random() % 50;

Discussion in 'Mac Programming' started by larswik, Aug 21, 2010.

  1. larswik macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    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;
    }
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. larswik thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    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?
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    There is no list, other than the header file itself.
     

Share This Page