title: Random number generator - variable length
body: <p>Currently my program (see below) generates random strings (made of numbers) from 8 - 12 characters in length.</p>
  
  <pre><code>public static string GenerateNewCode(int CodeLength)
  {
      string newCode = String.Empty;
      int seed = unchecked(DateTime.Now.Ticks.GetHashCode());
      Random random = new Random(seed);
  
      // keep going until we find a unique code       `
      do
      {
          newCode = random.Next(Convert.ToInt32(Math.Pow(10, CodeLength - 1)), Convert.ToInt32(Math.Pow(10, CodeLength) - 1)).ToString("0000");
      }
      while (!ConsumerCode.isUnique(newCode));
  
      // return
      return newCode;
  }
  </code></pre>
  
  <p>However, their is a problem with the method, when the <code>codeLength</code> is 10 or greater it causes error because 10<sup>9</sup> is greater than <code>int32.MaxValue</code>.</p>
  
  <p>Not sure how to get around this issue.</p>