title: Generate random alphanumeric string with condition in C#
body: <p>According to following code , I need to generate a string in different cases based on the method input. My issue is where I wanna generate <strong>9A9A</strong> (at least 1 number and 1 letter) or <strong>9A9A9A</strong> (at least 2 numbers and 2 letters). In most cases, this conditions is not met.</p>
  
  <pre><code>private AuthMessage GetAuthCode(string CodeType) //(out string Message)
      {
          Guid Guid = Guid.NewGuid();
          Random Random = new Random();
          string AuthCode = string.Empty;
          string RefCode = string.Empty;
  
          RefCode = Guid.ToString("N");
  
          switch (CodeType)
          {
              case "0": //9999
                  {
                      AuthCode = Random.Next(1000, 9999).ToString();
                      break;
                  }
              case "1": //99999
                  {
                      AuthCode = Random.Next(10000, 99999).ToString();
                      break;
                  }
              case "2": //999999
                  {
                      AuthCode = Random.Next(100000, 999999).ToString();
                      break;
                  }
              case "3": //999-999
                  {
                      AuthCode = Regex.Replace(Random.Next(100000, 999999).ToString(), @"^(.{3})(.{3})$", "$1-$2");
                      break;
                  }
              case "4": //9A9A
                  {
                      AuthCode = Guid.ToString("N").Substring(14, 4).ToUpper();
                      break;
                  }
              case "5": //9A9A9
                  {
                      AuthCode = Guid.ToString("N").Substring(15, 5).ToUpper();
                      break;
                  }
              case "6": //9A9A9A
                  {
                      AuthCode = Guid.ToString("N").Substring(6, 6).ToUpper();
                      break;
                  }
              case "7": //9A9-A9A
                  {
                      AuthCode = Regex.Replace(Guid.ToString("N").Substring(6, 6), @"(.{3})(.{3})", @"$1-$2").ToUpper();
                      break;
                  }
              case "8": //9A9-A9A
                  {
                      AuthCode = Regex.Replace(Regex.Replace(Convert.ToBase64String(Guid.ToByteArray()), "[/+=]", "").Substring(0, 6), @"(.{3})(.{3})", @"$1-$2").ToUpper();
                      break;
                  }
              default:
                  {
                      AuthCode = Random.Next(1000, 9999).ToString();
                      break;
                  }
          }
  
          AuthMessage Response = new AuthMessage();
          Response.AuthCode = AuthCode;
          Response.RefCode = RefCode;
  
       return Response;
      }
  </code></pre>