title: Swift - Good random node generation SpriteKit
body: <p>i try to creating a game where you need to avoid objects (nodes), and I wan't to generate these node at a random position (out of the screen, on the right) and with an action, the nodes cross the screen to the left. But how can I create a good random generation, so that there is no two nodes on the same position or too close.</p>
  
  <p>I have a timer in the didMoveToView method :</p>
  
  <pre><code>nodeGenerationTimer = NSTimer.scheduledTimerWithTimeInterval(2, target: self, selector: Selector("nodeGeneration"), userInfo: nil, repeats: true)
  </code></pre>
  
  <p>And the function to generate the node every 2 seconds :</p>
  
  <pre><code>func nodeGeneration() {
  
  
      var randomX = CGFloat(Int(arc4random()) % sizeX)
      println(randomX)
  
  
      let node = SKSpriteNode(imageNamed: "node")
      node.anchorPoint = CGPointMake(0.5, 0.5)
      node.size.width = self.size.height / 8
      node.size.height = bin.size.width * (45/34)
      node.position = CGPointMake(self.size.width + randomX, ground1.size.height / 2 + self.size.height / 14)
      node.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: node.size.width, height: node.size.height))
      node.physicsBody?.dynamic = false
      self.addChild(node)
  
      let moveAction = SKAction.moveByX(-1, y: 0, duration: 0.005)
      let repeatMoveAction = SKAction.repeatActionForever(moveAction)
      node.runAction(repeatMoveAction)
  
  
  }
  </code></pre>
  
  <p>And I have a second problem, imagine a game where you need to avoid object, but you can jump on it, is it possible to detect if the user collide with the side of the node, or if he jump on its top. I think there is another way than create a physic body on the side, and one on the top !</p>
  
  <p>Thanks for your help !</p>