Last active
August 29, 2015 14:06
-
-
Save 0V/628f28c25b165b896c43 to your computer and use it in GitHub Desktop.
ちとくちんち~~~~ん
This file contains hidden or 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.Linq; | |
using System.Security.Cryptography; | |
using System.Text; | |
namespace Util | |
{ | |
public class ChitokuChin | |
{ | |
private static readonly string chars = "ちとくちん"; | |
public static void StartChitokuChin() | |
{ | |
var chitoq = new Queue<char>(); | |
foreach (var c in GetRandomString(5)) | |
chitoq.Enqueue(c); | |
int count = 1; | |
while (true) | |
{ | |
if (chitoq.SequenceEqual("ちとくちん")) | |
{ | |
foreach(var c in chitoq) | |
Console.Write(c); | |
Console.WriteLine(Environment.NewLine +"ちとくちんち~~~~ん!!!{0}回目でちとくちん", count + 4); | |
break; | |
} | |
count++; | |
Console.Write(chitoq.Dequeue()); | |
chitoq.Enqueue(GetRandomString(1)[0]); | |
} | |
} | |
private static string GetRandomString(int length) | |
{ | |
var sb = new StringBuilder(length); | |
for (int i = 0; i < length; i++) | |
sb.Append(chars[GetRandomNumber()]); | |
return sb.ToString(); | |
} | |
private static int GetRandomNumber() | |
{ | |
var bs = new byte[4]; | |
var rng = new RNGCryptoServiceProvider(); | |
rng.GetBytes(bs); | |
var num = BitConverter.ToInt32(bs, 0); | |
return Math.Abs(num % chars.Length); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment