Advertisement
tolikpunkoff

GenRandomString

Mar 26th, 2017
1,863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1.         string GenRandomString(string Alphabet, int Length)
  2.         {
  3.             //string Ret = "";
  4.             Random rnd = new Random();            
  5.             StringBuilder sb = new StringBuilder(Length-1);
  6.             int Position = 0;
  7.                        
  8.             for (int i = 0; i < Length; i++)
  9.             {
  10.                 Position = rnd.Next(0, Alphabet.Length-1);
  11.                 sb.Append(Alphabet[Position]);
  12.                 //Ret = Ret + Alphabet[Position]; //- так делать не стоит, в данном случае StringBuilder дает явный выигрыш в скорости
  13.             }
  14.            
  15.             //return Ret;
  16.  
  17.             return sb.ToString();
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement