Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandomUtil中limitInteger获取结果分布不均 #8

Open
ETRick opened this issue Sep 6, 2018 · 3 comments
Open

RandomUtil中limitInteger获取结果分布不均 #8

ETRick opened this issue Sep 6, 2018 · 3 comments

Comments

@ETRick
Copy link

ETRick commented Sep 6, 2018

由于用了四舍五入最左端和最右端的两个数字出现的概率是中间其他数字的一半

@yicaoyimuys
Copy link
Owner

有什么好的实现方法吗,用Math.floor吗

@ETRick
Copy link
Author

ETRick commented Sep 12, 2018

是的,我改成这样了
public limitInteger($from: number, $end: number): number { return Math.floor(this.limit($from, $end + 1)); }
结果是左闭右闭,不加一就是左闭右开

@yicaoyimuys
Copy link
Owner

ok 多谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants