我創建一個返回10的倍數的函數?如何創建一個隨機擴展,返回10的倍數?
public static int NextInt(this Random rnd, int min = 0, int max = 1)
{
if (rnd == null) throw new ArgumentNullException("rnd");
if (min >= max) throw new InvalidOperationException();
var delta = max - min;
return min + (int)(rnd.NextDouble() * delta + min);
}
public static int MultipleOf10(this Random rnd, int minZeros = 1,
int maxZeros = 10)
{
if (rnd == null) throw new ArgumentNullException("rnd");
int pow = NextInt(rnd, minZeros, maxZeros);
return (int)Math.Pow(10, pow);
}
我對這兩個功能有疑問。第一個必須與Next()類似,另一個必須返回十的倍數。
你能指出我在哪裏修復它嗎?因爲我幾乎可以肯定這一點。
你的疑問到底是什麼? – 2012-01-16 19:52:45
多少10,還是10的冪?他們非常不同。 – 2012-01-16 19:54:45
比第一個像Random.Next()工作,並且另一個必須返回十的倍數像.. 10,1000,100,100000 .. 那麼,權力.. – 2012-01-16 19:55:09