Belajar Buat Random String di C#

Trick ini sering saya Gunakan sewaktu ingin membuat string2.. yang unix yah bisa di pake buat No ID ato pun Random Password Secara automatis Pada Sistem ane.. yah mari kita pelototin codenya ok...@_+

private string Acak-Acak(int Length)
{



string[] Characters = new string[56];

Characters[0] = "a";

Characters[1] = "b";

Characters[2] = "c";

Characters[3] = "d";

Characters[4] = "e";

Characters[5] = "f";

Characters[6] = "g";

Characters[7] = "h";

Characters[8] = "j";

Characters[9] = "k";

Characters[10] = "m";

Characters[11] = "n";

Characters[12] = "p";

Characters[13] = "q";

Characters[14] = "r";

Characters[15] = "s";

Characters[16] = "t";

Characters[17] = "u";

Characters[18] = "v";

Characters[19] = "w";

Characters[20] = "x";

Characters[21] = "y";

Characters[22] = "z";

Characters[23] = "A";

Characters[24] = "B";

Characters[25] = "C";

Characters[26] = "D";

Characters[27] = "E";

Characters[28] = "F";

Characters[29] = "G";

Characters[30] = "H";

Characters[31] = "J";

Characters[32] = "K";

Characters[33] = "L";

Characters[34] = "M";

Characters[35] = "N";

Characters[36] = "P";

Characters[37] = "Q";

Characters[38] = "R";

Characters[39] = "S";

Characters[40] = "T";

Characters[41] = "U";

Characters[42] = "V";

Characters[43] = "W";

Characters[44] = "X";

Characters[45] = "Y";

Characters[46] = "Z";

Characters[47] = "2";

Characters[48] = "3";

Characters[49] = "4";

Characters[50] = "5";

Characters[51] = "6";

Characters[52] = "7";

Characters[53] = "8";

Characters[54] = "9";



Random RandChar = new Random();

string Password = "";



for (int i = 0; i < Length; i++)

{

Password += Characters[RandChar.Next(0, 55)];

}



return Password;

}


Related Articles






IP

Followers

 

Copyright © 2009 by ::EXPLORE::