标签:
1 static void Main(string[] args) 2 { 3 MyRandom mr = new MyRandom(8);//相同的种子,每次都会生成相同的随机数列,为了保证生成的随机数不同,就要每次都要有不同的种子,Envoironment.TickCount 4 for (int i = 0; i < 10; i++) 5 { 6 Console.WriteLine(mr.Next()); ; 7 } 8 Console.ReadKey(); 9 } 10 } 11 class MyRandom 12 { 13 private int seed;//字段seed 14 public MyRandom(int seed)//构造函数 15 { 16 this.seed = seed; 17 } 18 public int Next() 19 { 20 int next = (seed * 29 + 37) % 1000; 21 seed = next; 22 return next; 23 } 24 }
标签:
原文地址:http://www.cnblogs.com/lucyliang/p/4749171.html