Skip to content

Instantly share code, notes, and snippets.

@0V
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0V/628f28c25b165b896c43 to your computer and use it in GitHub Desktop.
Save 0V/628f28c25b165b896c43 to your computer and use it in GitHub Desktop.
ちとくちんち~~~~ん
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