Berikut contoh kode program untuk mengenerate dan menyimpan hasil generate tersebut ke dalam file textNormal 0 MicrosoftInternetExplorer4 st1\:*{behavior:url(#ieooui) } /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman";}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace GeneratePass
{
class Program
{
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
string path = "D:\\Number.txt";
ArrayList myArrayList = new ArrayList();
for (int i = 0; i <= 100000; i++)
{
string password = CreateRandomPassword(4);
if (!myArrayList.Contains(password))
{
myArrayList.Add(password);
}
}
foreach(string pass in myArrayList )
{
sb.AppendLine(pass);
}
File.AppendAllText(path, sb.ToString());
}
private static string CreateRandomPassword(int passwordLength)
{
string allowedChars = "0123456789";
char[] chars = new char[passwordLength];
Random rd = new Random();
for (int x = 0; x < passwordLength; x++)
{
chars[x] = allowedChars[rd.Next(0, allowedChars.Length)];
}
return new string(chars);
}
}
}
0 komentar:
Posting Komentar