Quote:
Originally Posted by smasher
In general, you want to make an array of your (images / strings,) then pick a random number, then grab that Item from the array. Something like this:
Code:
//create the array
NSArray *myArray= [NSArray arrayWithObjects: @"Yes",@"No",@"File Not Found", 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
NSLog(@"The item I picked is: %@", item);
That's 4 bits of cocoa magic, and one bit of plain-old C magic.
|
it works|||||but i want to display an images randomly.........how to display the image is my question........