随机数 字母 数字
随机数 字母 数字
//len:随机数长度。beginRange,endRange:为"0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ"这段字符串的范围
1 private string GetRandomCharNum(int len, int beginRange, int endRange) 2 { 3 string ret = null; 4 string str = @"0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ"; 5 var seed = Guid.NewGuid().GetHashCode(); 6 Random random = new Random(seed); 7 for (int i = 0; i < len; i++) 8 { 9 ret += str.Substring(beginRange + random.Next(endRange), 1); 10 } 11 return ret; 12 }