Skip to content

Instantly share code, notes, and snippets.

@0V
Created June 21, 2014 13:29
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/60b9e004ea5345651eaa to your computer and use it in GitHub Desktop.
Save 0V/60b9e004ea5345651eaa to your computer and use it in GitHub Desktop.
using System;
using System.Text;
namespace ExperimentStap
{
class Program
{
static readonly string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYG";
static void Main(string[] args)
{
Experiment();
Console.ReadLine();
}
static void Experiment()
{
int count = 0;
while(true)
{
count++;
var str = GetRandomString(4);
Console.Write(str+"細胞 ");
if (str == "STAP")
{
Console.WriteLine("{0}回目で陽性かくにん! よかった☆", count);
break;
}
}
}
static string GetRandomString(int length)
{
var sb = new StringBuilder(length);
for (int i = 0; i < length; i++)
sb.Append(chars[GetRandomNumber()]);
return sb.ToString();
}
static int GetRandomNumber()
{
var bs = new byte[4];
var rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bs);
var num = System.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