我想实现以时间为种子产生伪随机数,在一端输入一个时间比如2011-5-10 12:37 系统会自动生成一个随机数;在另一端输入一个时间比如2011-5-10 12:40,只要和另一端输入的时间不超过20分钟就会产生相同的随机数。两端的操作是独立的,两端并不知道两各自输入的时间;所以我想把时间全部转化为分钟的形式,假设在一端输入的时间为2011-5-10 12:37,暂不考虑年,得到的分钟为X,以X为种子产生一个随机数A。在另一端假如输入时间为2011-5-10 12:42,得到的分钟为Y,以Y为种子产生一个随机数B。只要Y-X不大于20,A就等于B。但是由于操作是独立的,X的信息并不知道。请求帮助,多谢
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DateTime dt = DateTime.ParseExact("2011-05-10 20:27:22", "yyyy-MM-dd HH:mm:ss", null);
string str = dt.ToString("yyyyMMddHH") + (dt.Minute / 20).ToString();
int Seed = str.GetHashCode();
Random r = new Random(Seed);
Console.WriteLine(r.Next(0, 100));
}
}
}
int result2=number[y];