Returns a random double in the specified range.

Use Random.NextDouble() to generate a random value and map it to the desired range using multiplication.

代码实现

public static partial class _30s 
{
  public static double RandomDoubleInRange(double min, double max) 
  {
    return (new Random().NextDouble() * (max - min)) + min;
  }
}

使用样例

_30s.RandomDoubleInRange(0.5, 5); // 2.20486941011849