title: Random number range, exclude 0
body: <p>I have the following function that generates a random number between -10 and 2:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;time.h&gt;
  
  static int
  getRandomReturnCode(void)
  {
      int N = 2,
          M = -10;
  
      srand(time(NULL));
  
      r = M + rand() / (RAND_MAX / (N - M + 1) + 1);
  
      if (r == 0){
          getRandomReturnCode();
      }
  
      return r;
  }
  </code></pre>
  
  <p>Currently, if a return code of 0 (success) is returned, it will recursively call the function over until a non-zero return code is met and returned. What can I do to improve my code such that 0 is excluded from the range of randomly chosen numbers?</p>