随机生成指定长度的字符串

   public static string random(int length = 10)
        {
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            var random = new Random();
            var randomString = new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
            return randomString;
        }

  

public static string RandomStringStrongest(int length)
    {
        const string chars = @"!#%&/()=?'*<>-_+|0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        return new string(Enumerable.Repeat(chars, length)
          .Select(s => s[random.Next(s.Length)]).ToArray());

  

posted @ 2022-05-18 21:55  Charltsing  阅读(245)  评论(0编辑  收藏  举报