Is it possible somehow to make this non repeated? Im reading on the internet about the Fisher Yates method and Im wondering if its any easy way to use it in this easy codes.
Fisher-yates shuffle method
For example exchange the "% 6;" to some function?
Fisher-yates shuffle method
Code:
- (void)shuffleArray:(NSMutableArray *)array {
//fisher-yates shuffle
for (int i = [array count] - 1; i > 0; i--) {
int j = arc4random() % [array count];
[array exchangeObjectAtIndex:i withObjectAtIndex:j];
}
}
For example exchange the "% 6;" to some 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;
}
}