title: How can i make a random sound array with objective c?
body: <p>So i've done the tutorial where you code a button so that when you press it a sound plays. I'm trying to modify it so that when the button is pressed, a random sound plays.</p>
  
  <p>here is the code:</p>
  
  <p>viewcontroller.h</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;AudioToolbox/AudioToolbox.h&gt;
  
  @interface STViewController : UIViewController
  
  - (IBAction)playAudio:(id)sender;
  
  @property (nonatomic, strong) NSArray *sounds;
  
  @end
  </code></pre>
  
  <p>viewcontroller.m</p>
  
  <pre><code>#import &lt;AVFoundation/AVFoundation.h&gt;
  #import "STViewController.h"
  
  @interface STViewController ()
  
  @property (weak, nonatomic) IBOutlet UIButton *playAudio;
  
  @end
  
  @implementation STViewController
  
  
  - (IBAction)playAudio:(id)sender {
      AVAudioPlayer *audioPlayer;
      NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"Woof" ofType:@"mp3"];
      NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
      NSError *audioError = [[NSError alloc] init];
      audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&amp;audioError];
  
      if (!audioError) {
          [audioPlayer play];
          NSLog(@"Woof!");
      }
      else {
          NSLog(@"Error!");
      }
  }
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  
  
  @end
  </code></pre>
  
  <p>I've been dabbling with something along these lines</p>
  
  <pre><code>- (NSArray *)sounds
  {
      NSArray *sounds = [NSArray arrayWithObjects:
                         @"Woof.mp3",
                         @"Meow.mp3",
                         @"tweet.mp3",
                         @"Squeak.mp3",
                         @"Moo.mp3",
                         @"Croak.mp3",
                         @"Toot.mp3",
                         @"Quack.mp3",
                         @"Blub.mp3",
                         @"OWOwOw.mp3",
                         @"Fox.mp3",
                         nil];
  
      return sounds;
  }
  </code></pre>
  
  <p>but i'm not really sure how to make it random or even implement in in the code that I have going right now.  Anyone have any ideas?</p>