Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 02-01-2009, 07:53 PM   #14 (permalink)
PhillipJames
New Member
 
Join Date: Feb 2009
Posts: 2
Default Seems to not be random??

I am also a new programmer and every time it runs, I get the same order of answers - I have put 6 values in the array and they appear - 6, 3, 5, 5, 6, 2, 3, 5, 2, 4 ......

I can close the sim, recompile and sure enough they appear in this order everytime.

Any ideas?

==
NSArray *myArray= [NSArray arrayWithObjects: @"1111",@"2222",@"3333",@"4444",@"5555",@"6666" , nil];
int length = [myArray count];

//choose an item - C magic happens here
int chosen = (float)random() * length /RAND_MAX;

NSString *item = [myArray objectAtIndex: chosen];
lblText.text = [NSString stringWithFormat: @"%@", item];
PhillipJames is offline   Reply With Quote
 
Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,181
Threads: 38,954
Posts: 170,900
Top Poster: smasher (2,565)
Welcome to our newest member, Zephyros
Powered by vBadvanced CMPS v3.1.0

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