注意,不是数字也不是字母,是符号,例如“】【=--=-0=-0……*@(#!@&#)!(@#。,”
生成的符号数量是变量,例如随机生成包含5个符号的字符串。这样如何生成呢

解决方案 »

  1.   

            public static string RandomStrX(int pStrLen,int seed ) {
                string ct = @"~!@#$%^&*()_+-={}|[]\:;'<>?,./";
                string code = "";
                int randValue = -1;
                Random rand = new Random(unchecked((int)DateTime.Now.Ticks + seed));
                for (int i = 0; i < pStrLen; i++) {
                    randValue = rand.Next(0, ct.Length - 1);
                    code += ct[randValue];
                }
                return code;
            }
      

  2.   


    请问参数seed  是什么?
      

  3.   

    seed 随便乱定义的,因为是采用时间做种子,如果连续调用 RandomStrX,会得到同样的值,
    所以额外增加一个 seed 参数,允许更改种子值。string s1 = RandomStrX(10,1)
    string s2 = RandomStrX(10,2)
    string s3 = RandomStrX(10,3)