title: Swift: Error: Thread 1: EXC_BAD_INSTRUCTION on update function
body: <p>I am trying to make a simple application with rain effect. To create this I am using a simple spark image and make it fall from a cloud. However, when I am attempting to use the random function to randomly generate a random number for the x-coordinate position for the spark to appear, xCode throws an unexpected error:</p>
  
  <p><strong>Thread 1: EXC_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode=0x0)</strong></p>
  
  <p>Here is the code used to create this simple application:</p>
  
  <pre><code>import Foundation
  import SpriteKit
  
  class Particles: SKScene{
  
      let cloud = SKSpriteNode(imageNamed: "cloud")
  
      override func didMoveToView(view: SKView) {
          cloud.size = CGSize(width: 210, height: 100)
          cloud.position = CGPoint(x:self.frame.size.width/2, y:self.frame.size.height*0.9)
          cloud.anchorPoint = CGPoint(x:0.5,y:0.5)
          self.addChild(cloud)
  
  //        var rain = SKEmitterNode(fileNamed: "rainParticle.sks")
  //        rain!.position = CGPoint(x:cloud.position.x, y:cloud.position.y-cloud.size.height/2)
  //        self.addChild(rain!)
      }
  
      func particle_spawn(pos_x:Int){
          let particle = SKSpriteNode(imageNamed: "spark")
          particle.name = "spark"
          particle.size = CGSize(width: 10, height:10)
          particle.position = CGPoint(x: cloud.position.x+CGFloat(pos_x), y: cloud.position.y-cloud.size.width/2)
          self.addChild(particle)
          let fall = SKAction.moveTo(CGPoint(x:0,y:0), duration: 1)
          particle.runAction(fall)
      }
  
      override func update(currentTime: CFTimeInterval) {
          /* Called before each frame is rendered */
          let distance_change = Int(arc4random_uniform(UInt32(40))-20)
          particle_spawn(distance_change)
      }
  
  }
  </code></pre>
  
  <p>Does anyone know how to fix this error? If yes, can you explain me what this error means and why I get it with as much explanation as possible please?</p>
  
  <p><strong>NOTE:</strong> English is not my first language.</p>
  
  <p>Thank you all!</p>