无意之间的发现。绝对出乎你意料的输出结果。程序也会忽悠你。
今日无聊,随便写点东西练手。
想写个获取随机数的类
然后调用,输出。
这是没啥问题。
然后循环N次输出呢?
出来的是N个是随机数吗?
呵呵,你果断被自己写的代码骗了。
废话不多说,上代码了。
自己运行下试试。结果绝对让你惊讶。
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace random{ class Program { static void Main(string[] args) { for (int i = 0; i < 100; i++) { sj s = new sj(); int N = s.sjff(1, 100); Console.WriteLine(n); } Console.ReadKey(); } public class sj { public int sjff(int a, int b) { Random r = new Random(); int N = r.Next(a, b); return N; } } }}