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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 11-25-2009, 12:39 PM   #11 (permalink)
smasher
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

To the original posters from last year: random() always returns the same set of numbers if you don't seed it. arc4random() is easier to use; it seeds itself on the first call. Just use arc4random()%10 to get a number from 0 to 9 inclusive.

mooman576: Do you have your numbers in some sort of NSarray? Then you can shuffle them by sorting the array, but using a sort function that returns random results. Like this:

Code:
NSArray *sortedArray;
sortedArray = [anArray sortedArrayUsingFunction:shuffleSort context:NULL];
The shuffleSort function would look like this:

Code:
//this function gets called by sortedArrayUsingFunction: 
//when sorting the array
NSInteger shuffleSort(id num1, id num2, void *context){

   int result = arc4random()%3; // pick a number 0,1,2

   if (result==0)
      return NSOrderedAscending;
   if (result==1)
      return NSOrderedDescending

   return NSOrderedSame;
}
__________________

Free Games!
smasher is offline   Reply With Quote
 

» Advertisements
» Online Users: 886
21 members and 865 guests
13dario13, ADY, apatsufas, baja_yu, David-T, EmidoroSmibre, esespanol, girish99, glusacontroll, iekei, ilmman, iram901, ketaskin, nestochi, niieueii, parkash_goswami, Pauluz85, ryanninan, stanny, tresadl80, _MAK88_
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,372
Threads: 93,996
Posts: 402,447
Top Poster: BrianSlick (7,978)
Welcome to our newest member, glusacontroll
Powered by vBadvanced CMPS v3.1.0

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