1
/// <summary>
2
/// 创建随机字符串
3
/// </summary>
4
/// <param name="codeCount">随机数的位数</param>
5
/// <returns></returns>
6
public static string CreateRandomCode_Len54(int codeCount)
7
{
8
string allChar = "1,A,2,S,3,D,4,F,5,G,6,H,7,J,8,K,9,L,8,M,7,N,6,B,5,V,4,C,3,X,2,Z,1,P,9,Q,8,Z,7,W,6,I,5,E,4,U,3,R,2,Y,1,T,E,X,G,Q";
9
string[] allCharArray = allChar.Split(',');
10
string randomCode = "";
11
int temp = -1;
12![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
Random rand = new Random();
14
for(int i = 0; i < codeCount; i++)
15
{
16
if(temp != -1)
17
{
18
rand = new Random(i*temp*((int)DateTime.Now.Ticks));
19
}
20
int t = rand.Next(54);
21
if(temp == t)
22
{
23
return CreateRandomCode_Len54(codeCount);
24
}
25
temp = t;
26
randomCode += allCharArray[t];
27
}
28
return randomCode;
29
}
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
3
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
4
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
5
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
6
![](https://zsy.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
8
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
9
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
10
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
11
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
12
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
14
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
15
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
17
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
18
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
19
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
20
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
21
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
22
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
23
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
24
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
25
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
27
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
28
![](https://zsy.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
29
![](https://zsy.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)