C#获取随机数,并且包括获取几位小数

/// <summary>
/// 获取随机数
/// </summary>
/// <param name="minimum">最小值</param>
/// <param name="maximum">最大值</param>
/// <param name="Len">小数点保留位数</param>
/// <returns></returns>
public double GetRandomNumber(double minimum, double maximum, int Len)
{
    System.Threading.Thread.Sleep(1);//防止获取随机太快时 获取的是同一个随机数
    Random random = new Random(DateTime.Now.Millisecond);
    return Math.Round(random.NextDouble() * (maximum - minimum) + minimum, Len);
}

评论