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

ryans79

macrumors regular
Original poster
Apr 12, 2009
226
0
Hello,

This is my first mac app, works like a charm (as i got it from a book) just want to add a little functionality to it... but dont know how (problem with learning by myself and a book is cant really ask the "instructor" if i want to add something :( )

Heres the code that i am using:
#import "Foo.h"

@implementation Foo

- (IBAction)generate:(id)sender
{
// Generate a number between 1 and 100 inclusive
int generated;
generated = (random() % 100) + 1;
NSLog(@"generated = %d", generated);
// Ask the text field to change what it is displaying
[textField setIntValue:generated];
}


- (IBAction)seed:(id)sender
{
// Seed the random number generator with the time
srandom(time(NULL));
[textField setStringValue:mad:"Generator seeded"];
}
@end

Heres what i want to do, in the text where it says Generator seeded, i want to add the srandom number as well.

I know it must be simple, but since this is my first app im just getting used to the basics.

Thanks!
 
couldnt find the word before, but i guess i want to "concatenate" the srandom number after the message.

Thanks again!
 
One possible problem is that srandom returns void, so there's no result to print. If you want to be sure you print the same value as you pass in to srandom, you'll need to store the result of the time call, since this is always changing.

Once you know what you want to print, look into the things robbieduncan mentioned.

-Lee
 
Will do, i think i just need to keep reading and doing the examples before getting "creative" and extending the functionality.

I'll come back to this once the book tells me how to go through the documentation, it was mentioned in the earlier chapter, but will be coming up in more detail in the coming chapters.

Cheers!
°°
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.