Created
July 2, 2015 01:51
-
-
Save taross-f/7f214ae89d52bdf8a551 to your computer and use it in GitHub Desktop.
This tool generates some random serialcodes into a txt file. You can choose any characters that they include.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
namespace GenerateSerialCode | |
{ | |
/// <summary> | |
/// かぶりなし 文字種類指定 個数指定 でシリアルコードを生成する | |
/// </summary> | |
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
string characters; | |
int charCount; | |
int count; | |
do | |
{ | |
Console.WriteLine("使用する文字を指定してください。:\n"); | |
characters = Console.ReadLine(); | |
if (string.IsNullOrEmpty(characters)) | |
{ | |
Console.WriteLine("文字が指定されていないです。"); | |
Console.ReadLine(); | |
return; | |
} | |
Console.WriteLine("文字数を指定してください。:\n"); | |
int.TryParse(Console.ReadLine(), out charCount); | |
Console.WriteLine("作成する個数を指定してください。:\n"); | |
int.TryParse(Console.ReadLine(), out count); | |
Console.WriteLine("使用する文字:{0}\n個数:{1}\n文字数:{2}\nでよければyを入力してください。\ny以外は初めからやり直します。", characters, count, charCount); | |
} while (Console.ReadLine() != "y"); | |
Console.WriteLine("生成開始"); | |
var codes = new HashSet<string>(); | |
var random = new Random(); | |
while (codes.Count < count) | |
{ | |
var code = new StringBuilder(charCount); | |
Enumerable.Range(1, charCount) | |
.Select(_ => | |
{ | |
code.Append(characters[random.Next(0, characters.Length)]); | |
return 0; | |
}) | |
.ToArray(); | |
codes.Add(code.ToString()); | |
if (codes.Count % 10000 == 0) | |
{ | |
Console.Write("."); | |
} | |
} | |
Console.WriteLine("生成完了"); | |
var outPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + | |
string.Format("{0:yyyyMMddHHmm}.txt", DateTime.Now); | |
File.WriteAllText(outPath, string.Join("\n", codes)); | |
Console.WriteLine("{0}に出力", outPath); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment