I am trying to create a random sound generator with no repeated sounds. I would like to use the fisher-yates algorithm. Can anyone please explain how I should go about making an nsmutable array of sound files that would apply to the shuffling algorithm found here: What's the Best Way to Shuffle an NSMutableArray?
Asked
Active
Viewed 56 times
0
-
Make an array of file names. – Sergey Kalinichenko Apr 18 '14 at 11:56
-
In this format? NSMutableArray *sounds = [NSMutableArray arrayWithObjects: @"sound1", @"sound2", nil]; And where exactly do I put this array? – user3451320 Apr 18 '14 at 12:27
-
The format is up to you. BTW, `arrayWithObjects` can be replaced with `@[@"sound1", @"sound2"]` syntax. – Sergey Kalinichenko Apr 18 '14 at 12:31
-
@dasblinkenlight that doesn't create a mutable array. – The Paramagnetic Croissant Apr 18 '14 at 12:42
-
@user3477950 Ah, you're right. `[@[@"sound1", @"sound2"] mutableCopy]` then? :) – Sergey Kalinichenko Apr 18 '14 at 12:43
-
@dasblinkenlight yes, supposedly. (Apple could have added some syntax for mutable literals, couldn't they?) – The Paramagnetic Croissant Apr 18 '14 at 12:44
-
Would this format be equally as successful or even better?: NSString *path = [[NSBundle mainBundle] pathForResource:@"SoundFileName" ofType:@"wav"]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path],&mySoundID); And I am still confused on how to get the array of these file names to follow the rules of that shuffle algorithm. – user3451320 Apr 18 '14 at 13:15