Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

Graves Robber
($1.99)

African Adventure
($0.99)

iTazer
($0.99)

ArtStudio
($3.99)

Pigs Vs Wolves
($1.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: 2,543
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.
__________________
smasher is online now   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,754
Threads: 38,524
Posts: 169,208
Top Poster: smasher (2,543)
Welcome to our newest member, labouhassan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:16 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.