title: How does VBA rand generate random numbers using the upperbound and lowerbound?
body: <p>so maybe this is redundant, maybe it's like asking why most humans are born with 5 fingers, the short answer in the end is always: because that's how it is and it just works, but I hate that answer and dammit I want to know how Rnd() function in VBA works. </p>
  
  <p>The MSDN for Ms Office Excel says that RND is defined as: </p>
  
  <p><code>Rnd[(number)] 'The optional number argument is a Single or any valid numeric expression.</code></p>
  
  <p>It goes on to say </p>
  
  <blockquote>
    <p>"The value of number determines how Rnd generates a random number: For
    any given initial seed, the same number sequence is generated because
    each successive call to the Rnd function uses the previous number as a
    seed for the next number in the sequence."</p>
  </blockquote>
  
  <p>followed by this: </p>
  
  <blockquote>
    <p>To produce random integers in a given range, use this formula:</p>
    
    <p><code>Int((upperbound - lowerbound + 1) * Rnd + lowerbound)</code></p>
  </blockquote>
  
  <p>so for example:<br>
  <code>Dim MyValue
  MyValue = Int((6 * Rnd) + 1)    ' Generate random value between 1 and 6.</code></p>
  
  <p>But how does that work? where are these numbers coming from? why does <code>6 * Rnd + 1</code> get you random number between 1 and 6, but <code>6 * Rnd + 5</code> gets you a number between 5 and 10?</p>
  
  <p>furthermore, if it was so apparent to the creators of VBA what formula to use to successfully narrow this down to a specific range, why not just have the RND function come with optional Ubound and Lbound arguments? I can't be the only one looking at that formula going what in the world is that?</p>
  
  <p>At the end of the day it works of course fine for any of my pseudo random number needs and maybe I'm looking a gift horse in the mouth but still! </p>
  
  <hr>
  
  <p>EDIT</p>
  
  <hr>
  
  <p>It occurs to me that this question might be based in Math itself. if you take a small integer what functions do you apply to make that integer fit in a specified range.. so can anyone explain how this formula works? </p>