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

请问如何限制正态随机数生成的区间? #1

Open
Jennal opened this issue May 30, 2019 · 2 comments
Open

请问如何限制正态随机数生成的区间? #1

Jennal opened this issue May 30, 2019 · 2 comments

Comments

@Jennal
Copy link

Jennal commented May 30, 2019

比如 rand() * (1.0 / RAND_MAX),可以得到 [0, 1) 之间的随机数,但是变换成正态分布以后,区间似乎就变得不可控了,请问你是如何处理这个问题的呢?@miloyip

@miloyip
Copy link
Owner

miloyip commented May 30, 2019

正态分布定义的范围是 [-∞, +∞],如果有实际需要就做 clamping 吧。

@Jennal
Copy link
Author

Jennal commented Jun 1, 2019

Clamping的话建议怎么做呢?
我想到的是2种方法:

  1. 如果超出范围,重新生成一次。但是这样的话,运算效率就有点不可控
  2. 如果超出范围,就直接取区间的最大值或最小值,但是这样的话,最大值和最小值的概率就会提高,整体上就不符合正态分布了。

不知道有没有更好的方法呢?

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