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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-01-2010, 10:45 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 3
Default Shuffle NSArray while keeping format

I need to randomize an NSArray that I have loaded with quiz questions. I have read other posts about randomizing NSArray, but I need to keep the elements in a specific order.

The array format is as follows:
@"Question1",@"ans1",@"ans2",@"ans3",@"ans4",@"cor rect answer",
@"Question2",@"ans1",@"ans2",@"ans3",@"ans4",@"cor rect answer",
and so on...

I would like to shuffle the array while keeping all these sets of 6 (the question and answer choices) next to each other. Any suggestions would be greatly appreciated.

Thank you.
mfoley89 is offline   Reply With Quote
Old 01-02-2010, 12:05 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
Default

I think you should have an array of arrays, and shuffle that. Trying to do it in one big array will require more code and be more confusing to boot.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 01-02-2010, 12:20 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
Default

Quote:
Originally Posted by smasher View Post
I think you should have an array of arrays, and shuffle that. Trying to do it in one big array will require more code and be more confusing to boot.
Or, better yet, design a class that contains a question and its answers, and then have a single array of those objects.
ChrisL is offline   Reply With Quote
Old 01-31-2010, 06:27 PM   #4 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 5
Default

have any body come with a more elaborated idea i am trying to accomplish that too.

Best regards
HP
quky is offline   Reply With Quote
Old 01-31-2010, 11:42 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 19
Default

What more needs to be said? ChrisL had the correct solution, above.
churn is offline   Reply With Quote
Old 02-01-2010, 12:07 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 5
Default

that would be to much for my little knowledge

just in case i think this is easier at least for me

c/p from another forum

You can create a class as mentioned before, or you could look at using plist or dictionaries. A plist/dictionary is basically an array or arrays. Therefore you would just have to randomly pick with object("array") you want to display.

Best regards
HP
quky is offline   Reply With Quote
Reply

Bookmarks

Tags
array, nsarray, randomize, shuffle

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 268
18 members and 250 guests
ADY, Alsahir, dacapo, Dani77, Desert Diva, djohnson, Duncan C, F_Bryant, Grinarn, HemiMG, jansan, linkmx, M@realobjects, macquitzon216, prchn4christ, smethorst, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:48 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0