title: Generate Random Numbers Between Two Numbers in Objective-C
body: <p>I have two text boxes and user can input 2 positive integers (Using Objective-C). The goal is to return a random value between the two numbers.</p>
  
  <p>I've used "man arc4random" and still can't quite wrap my head around it. I've came up with some code but it's buggy.</p>
  
  <pre><code>float lowerBound = lowerBoundNumber.text.floatValue;
  float upperBound = upperBoundNumber.text.floatValue;
  float rndValue;
  //if lower bound is lowerbound &lt; higherbound else switch the two around before randomizing.
  if(lowerBound &lt; upperBound)
  {
      rndValue = (((float)arc4random()/0x100000000)*((upperBound-lowerBound)+lowerBound));
  }
  else 
  {
      rndValue = (((float)arc4random()/0x100000000)*((lowerBound-upperBound)+upperBound));
  }
  </code></pre>
  
  <p>Right now if I put in the values 0 and 3 it seems to work just fine. However if I use the numbers 10 and 15 I can still get values as low as 1.0000000 or 2.000000 for "rndValue".</p>
  
  <p>Do I need to elaborate my algorithm or do I need to change the way I use arc4random?</p>