天天看點

建立随機字元串

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

建立随機字元串

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

建立随機字元串

        } 

本文轉自高海東部落格園部落格,原文連結:http://www.cnblogs.com/ghd258/archive/2005/11/07/270438.html,如需轉載請自行聯系原作者