您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

23 行
758 B

  1. using System;
  2. using System.Linq;
  3. namespace Infrastructure
  4. {
  5. public static class RandomGenerator
  6. {
  7. private static readonly string numbers = "0123456789";
  8. private static readonly string lowercases = "abcdefghijklmnopqrstuvwxyz";
  9. private static readonly string uppercases = lowercases.ToUpper();
  10. public static string GetRandomString(int length, bool number = true, bool lowercase = false, bool uppercase = false)
  11. {
  12. var pool = $"{(number ? numbers : "")}{(lowercase ? lowercases : "")}{(uppercase ? uppercases : "")}";
  13. var generator = new Random();
  14. return new string(Enumerable.Repeat(pool, length).Select(s => s[generator.Next(s.Length)]).ToArray());
  15. }
  16. }
  17. }