獲取隨機數
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; }