I kept messing with this. Kinda got it to work, but sometimes get the same response several times in a row (i.e. not seeming very random) and am getting "Warning: local declaration of 'myArray' hides instance variable" messages.
I stuck the following in my Controller.h file
Code:
NSArray *myArray;
@ property (nonatomic, retain) NSArray *myArray;
and the following in my Controller.m file
Code:
- (IBAction)hello:(id)sender {
//create the array
NSArray *myArray= [NSArray arrayWithObjects: @"Yes",@"No",@"Maybe", nil];
//get the length of the array
int length = [myArray count];
//choose an item - C magic happens here :)
int chosen = (float)random() * length /RAND_MAX;
//get that item
NSString *item = [myArray objectAtIndex: chosen];
//print that item
helloLabel.text = (@"THe item I picked is: %@", item);
}
hello is a label field that I'm outputting the text to display on screen. Still expect I'm doing something wrong. Help greatly appreciated. Thanks.