获取随机数
dom
举例:0-9 ui
Random random = new Random(); int j = random.Next(0, 9);
0、1两个值被取值的几率相等
code
int a = Math.Abs(Guid.NewGuid().GetHashCode()) % 2; if (a == 0) {} else if(a==1) {}
/// <summary> /// 获取等几率的小于最大数的非负随机数 /// </summary> /// <param name="n">最大数</param> /// <returns></returns> public static int Estimate(int n) { return Math.Abs(Guid.NewGuid().GetHashCode()) % n; }