title: Will the difference between RAND_MAX and UINT_MAX vary?
body: <p>My homework involves making random integers between <code>0</code> and <code>2^30</code>. Now, in the past we've learned that <code>rand()</code> only returns integers up to <code>RAND_MAX</code>, that this is less than <code>UINT_MAX</code>, and that we can use bit shifting to fill up that <code>UINT_MAX</code> capacity. From some reading I've done (here, on SO), I realise that this may not be a very good idea if the distribution of these numbers matters to me. Having said that, my professor has specified this method.</p>
  
  <p>My question is, by how much to bit shift? Will the difference between <code>RAND_MAX</code> and <code>UINT_MAX</code> always be such that there is a safe constant by which to bit shift? Or is there some initial probing that needs to be done to determine the number by which to bit shift? Should I just keep bit shifting by a little bit and checking against <code>UINT_MAX</code>?</p>
  
  <p>The reason I ask is that, <code>UINT_MAX</code> is defined to be at least a certain number (<code>65535</code>), but on my machine <code>UINT_MAX</code> is much bigger (<code>4294967295</code>). This got me worried that I might finish my homework over the weekend, arrive at school, and find everything not working well enough to submit.</p>
  
  <p>Thanks!</p>
  
  <p><strong>References:</strong></p>
  
  <p>I've read a couple of similar questions but couldn't garner an answer from them. </p>
  
  <p><a href="https://stackoverflow.com/questions/4945698/is-the-value-of-rand-max-always-2n-1">Is the value of <code>RAND_MAX</code> always <code>(2^n)-1</code>?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/1527108/generating-a-random-number-within-range-0-to-n-where-n-can-be-rand-max">generating a random number within range <code>0</code> to <code>n</code> where <code>n</code> can be <code>&gt; RAND_MAX</code></a></p>
  
  <p>Actually, the second question above makes me question the worth of doing this at all?</p>