标签:style blog http color os io for 2014
关键代码:
/// <summary> /// 生成设置范围内的Double的随机数 /// eg:_random.NextDouble(1.5, 2.5) /// </summary> /// <param name="random">Random</param> /// <param name="miniDouble">生成随机数的最大值</param> /// <param name="maxiDouble">生成随机数的最小值</param> /// <returns>当Random等于NULL的时候返回0;</returns> public static double NextDouble(this Random random, double miniDouble, double maxiDouble) { if (random != null) { return random.NextDouble() * (maxiDouble - miniDouble) + miniDouble; } else { return 0.0d; } }
测试代码:
static void Main(string[] args) { try { Random _random = new Random(); for (int i = 0; i < 10; i++) { Console.WriteLine(_random.NextDouble(1.5, 2.5)); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.ReadLine(); } }
测试结果:
标签:style blog http color os io for 2014
原文地址:http://www.cnblogs.com/Yan-Zhiwei/p/3904182.html