/// <summary> /// 乱数を生成する /// 位置母数(location parameter) 0 /// 尺度母数(scale parameter) 1 /// </summary> /// <returns></returns> public double NextDouble() { retry_point: double u1 = ud1.NextDouble(); double u2 = ud2.NextDouble(); if (u2 == 0.5) { goto retry_point; } double v1 = 2 * u1 - 1; double v2 = 2 * u2 - 1; double w = v1 * v1 + v2 * v2; if (1 <= w) { goto retry_point; } double y = v1 / v2; result = y; return(result); }
/// <summary> /// 乱数を生成する /// 標準偏差 1 /// </summary> /// <returns></returns> public double NextDouble() { retry_point: double u1 = ud1.NextDouble(); double u2 = ud2.NextDouble(); double v = u1 * u1 + u2 * u2; if (v <= 0 || 1 <= v) { goto retry_point; } double w = Math.Sqrt(-2 * Math.Log(v) / v); double y1 = u1 * w; double y2 = u2 * w; if (even) { result = y1; even = false; } else { result = y2; even = true; } return(result); }
/// <summary> /// 乱数を生成する /// 平均値 0 /// 標準偏差 1 /// </summary> /// <returns></returns> public double NextDouble() { retry_point: double u1 = ud1.NextDouble(); double u2 = ud2.NextDouble(); double v1 = 2 * u1 - 1; double v2 = 2 * u2 - 1; double v = v1 * v1 + v2 * v2; if (v <= 0 || 1 <= v) { goto retry_point; } double w = Math.Sqrt(-2 * Math.Log(v) / v); double y1 = v1 * w; double y2 = v2 * w; if (even) { result = y1; even = false; } else { result = y2; even = true; } result = Math.Exp(result); return(result); }