标签:
while (true) { Console.WriteLine("请输入你的姓名:"); string name1 = Console.ReadLine(); int seed1 = 0; if (name1.Length == 2) //名字为两个字 { seed1 = (int)Convert.ToChar(name1.Substring(0, 1)) + (int)Convert.ToChar(name1.Substring(1, 1)); } else //名字为三个字 { seed1 = (int)Convert.ToChar(name1.Substring(0, 1)) + (int)Convert.ToChar(name1.Substring(1, 1)) + (int)Convert.ToChar(name1.Substring(2, 1)); } Random rand1 = new Random(seed1); int yf1 = rand1.Next(10); //随机生成一个10以内的数字 Console.WriteLine("请输入你的姓名:"); string name2 = Console.ReadLine(); int seed2 = 0; if (name2.Length == 2) { seed2 = (int)Convert.ToChar(name2.Substring(0, 1)) + (int)Convert.ToChar(name2.Substring(1, 1)); } else { seed2 = (int)Convert.ToChar(name2.Substring(0, 1)) + (int)Convert.ToChar(name2.Substring(1, 1)) + (int)Convert.ToChar(name2.Substring(2, 1)); } Random rand2 = new Random(seed2); int yf2 = rand2.Next(10); if (Math.Abs(yf1 - yf2)>=4) { Console.WriteLine("你们很有缘分,好好珍惜吧!"); } else { Console.WriteLine("看来你们情深缘浅,好自为之吧"); } }
标签:
原文地址:http://www.cnblogs.com/jia520110270/p/4628767.html