创建随机字符串

1 ExpandedBlockStart.gif ContractedBlock.gif /**/ /// <summary>
 2InBlock.gif        /// 创建随机字符串
 3InBlock.gif        /// </summary>
 4InBlock.gif        /// <param name="codeCount">随机数的位数</param>
 5ExpandedBlockEnd.gif        /// <returns></returns>

 6 None.gif          public   static   string  CreateRandomCode_Len54( int  codeCount) 
 7 ExpandedBlockStart.gifContractedBlock.gif         dot.gif
 8InBlock.gif            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"
 9InBlock.gif            string[] allCharArray = allChar.Split(','); 
10InBlock.gif            string randomCode = ""
11InBlock.gif            int temp = -1
12InBlock.gif
13InBlock.gif            Random rand = new Random(); 
14InBlock.gif            for(int i = 0; i < codeCount; i++
15ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif
16InBlock.gif                if(temp != -1
17ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif
18InBlock.gif                    rand = new Random(i*temp*((int)DateTime.Now.Ticks)); 
19ExpandedSubBlockEnd.gif                }
 
20InBlock.gif                int t = rand.Next(54); 
21InBlock.gif                if(temp == t) 
22ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif
23InBlock.gif                    return CreateRandomCode_Len54(codeCount); 
24ExpandedSubBlockEnd.gif                }
 
25InBlock.gif                temp = t; 
26InBlock.gif                randomCode += allCharArray[t]; 
27ExpandedSubBlockEnd.gif            }
 
28InBlock.gif            return randomCode; 
29ExpandedBlockEnd.gif        }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值