Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 01-10-2009, 01:19 AM   #2 (permalink)
smasher
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

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.
__________________

Free Games!
smasher is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,622
Threads: 89,141
Posts: 380,329
Top Poster: BrianSlick (7,110)
Welcome to our newest member, shenehashri
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.