void Start()
{
System.Random random = new System.Random();
for (int i = 0; i < 10; i++)
{
Debug.Log(GetRandomNumber(random,3.14, 4.54, 2));
}
}
/// <summary>
/// 在一定范围内生成随机小数
/// </summary>
/// <param name="random"></param>
/// <param name="minimum">最小值</param>
/// <param name="maximum">最大值</param>
/// <param name="Len">保留小数点位数</param>
/// <returns></returns>
public double GetRandomNumber(System.Random random,double minimum, double maximum, int Len)
{
lock (random)
{
return Math.Round(random.NextDouble() * (maximum - minimum) + minimum, Len);
}
}
更多实现方法