Function returning random double with exponential distribution in range (a,b)
问题 I want to generate a random number from a to b . The problem is, the number has to be given with exponential distribution. Here's my code: public double getDouble(double low, double high) { double r; (..some stuff..) r = rand.NextDouble(); if (r == 0) r += 0.00001; return (1 / -0.9) * Math.Log(1 - r) * (high - low) + low; } The problem is that (1 / -0.9) * Math.Log(1 - r) is not between 0 and 1, so the result won't be between a and b . Can someone help? Thanks in advance! 回答1: I