最大值和最小值之间的ActionScript 3的随机数 [英] Actionscript-3 random numbers between max and min

查看:198
本文介绍了最大值和最小值之间的ActionScript 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?

这篇关于最大值和最小值之间的ActionScript 3的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆