最大值和最小值之间的ActionScript 3的随机数随机数、最大值、最小值、ActionScript

由网友(待我温柔似水淹死你可好)分享简介:我生成这个code最小值和最大值之间的随机数:I'm generating a random number between min and max with this code:return min + (max - min) * Math.random();和它的作品。然而,随机数是非常小的,通常在1〜3,即使最...

我生成这个code最小值和最大值之间的随机数:

I'm generating a random number between min and max with this code:

return min + (max - min) * Math.random();

和它的作品。然而,随机数是非常小的,通常在1〜3,即使最大为80。

And it works. However, the random numbers are very little usually between "1 or 3" even if the max is 80.

我怎样才能更好地在所有范围内分布的随机数?

How can I better distribute the random numbers over all range ?

感谢

推荐答案

我非常肯定的code你贴,返回分钟+(最大 - 最小)*的Math.random() ; ,应该返回分钟(含)和max(不含)之间均匀分布的随机数。我们没有理由为什么它会1和3之间的回报..你尝试跟踪的最小值和最大值,以确保他们是你认为他们是数字?

I am very sure that the code you posted, return min + (max - min) * Math.random(); , should return an evenly distributed random number between min (inclusive) and max (exclusive). There is no reason why it would return between 1 and 3.. Did you try tracing min and max to make sure that they are the numbers you think they are?

阅读全文

相关推荐

最新文章