Skip to content

Instantly share code, notes, and snippets.

@nathanclark
Created November 6, 2012 21:27
Show Gist options
  • Save nathanclark/4027691 to your computer and use it in GitHub Desktop.
Save nathanclark/4027691 to your computer and use it in GitHub Desktop.
// An example of how to trigger a random timer with a floor of 1 and a ceiling of 4;
-(void)random{
int randNum = rand() % (4 - 1) + 1; //create the random number.
NSLog(@"[DEBUG] random triggered %i", randNum);
// Choosing a random sound effect
NSString *filename = [NSString stringWithFormat:@"soundEffect%i",randNum];
NSString *filePath = [[NSBundle mainBundle] pathForResource:filename ofType:@"caf"];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:[NSURL fileURLWithPath:filePath]
error:&error];
if (error)
NSLog(@"Error: %@",
[error localizedDescription]);
else
[audioPlayer play];
[self performSelector:@selector(random) withObject:self afterDelay:randNum];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment