Created
June 21, 2014 13:29
-
-
Save 0V/60b9e004ea5345651eaa to your computer and use it in GitHub Desktop.
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.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