title: generate a unique id (globally )not more than 20 characters long containing only digits and letters, no special characters.
body: <p>This is my code that I am using to generate an ID.
  I am also stripping the result off any special characters like '=' and passing 14 as a parameter to this method.</p>
  
  <p>Sorry about not being more specific before, what I want is to generate a unique id not more than 20 characters long containing only digits and letters, no special characters. This ID can be generated from any computer from anywhere. I can't use GUID, since it's more than 20 characters long. This ID will be used as a report number.</p>
  
  <pre><code>static long counter; //store and load the counter from persistent storage every time      the program loads or closes.
  private static string CreateRandomString(int length)
      {
  
          length -= 12    ; //12 digits are the counter
          if (length &lt;= 0)
              throw new ArgumentOutOfRangeException("length");
          long count = System.Threading.Interlocked.Increment(ref counter);
          Byte[] randomBytes = new Byte[length * 3 / 4];
          RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
          rng.GetBytes(randomBytes);
  
          byte[] buf = new byte[8];
          buf[0] = (byte)count;
          buf[1] = (byte)(count &gt;&gt; 8);
          buf[2] = (byte)(count &gt;&gt; 16);
          buf[3] = (byte)(count &gt;&gt; 24);
          buf[4] = (byte)(count &gt;&gt; 32);
          buf[5] = (byte)(count &gt;&gt; 40);
          buf[6] = (byte)(count &gt;&gt; 48);
          buf[7] = (byte)(count &gt;&gt; 56);
          return Convert.ToBase64String(buf) + Convert.ToBase64String(randomBytes);
  
      }
  </code></pre>