is possible somehow make non repeated? im reading on internet fisher yates method , im wondering if easy way use in easy codes.
fisher-yates shuffle method
code:
- (void)shufflearray:(nsmutablearray *)array { //fisher-yates shuffle (int = [array count] - 1; > 0; i--) { int j = arc4random() % [array count]; [array exchangeobjectatindex:i withobjectatindex:j]; } }
for example exchange "% 6;" function?
code:
-(ibaction)randomwords:(id)sender { int ran = arc4random() % 6; switch (ran) { case 0: textlabel.text = @"cat"; break; case 1: textlabel.text = @"dog"; break; case 2: textlabel.text = @"fish"; break; case 3: textlabel.text = @"horse"; break; case 4: textlabel.text = @"bird"; break; case 5: textlabel.text = @"f"; break; default: break; } }
i'm confused, looking do?
trying shuffle bunch of objects?
call rand() repeatedly , assign generated value each object. sort objects in ascending order random value. seed random when app launches current time, "random" values aren't same each time app closed , started again.
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
No comments:
Post a Comment