Yly*_*Yly 1 random normal-distribution range julia
问题:如何在Julia的高斯分布中在区间[0,1]中生成随机数?
我收集randn是生成正态分布随机数的方法,但文档对如何指定范围的描述是非常不透明的.
使用Distributions包.如果您还没有:
using Pkg ; Pkg.add("Distributions")
Run Code Online (Sandbox Code Playgroud)
然后:
using Distributions
mu = 0 #The mean of the truncated Normal
sigma = 1 #The standard deviation of the truncated Normal
lb = 0 #The truncation lower bound
ub = 1 #The truncation upper bound
d = Truncated(Normal(mu, sigma), lb, ub) #Construct the distribution type
x = rand(d, 100) #Simulate 100 obs from the truncated Normal
Run Code Online (Sandbox Code Playgroud)
或全部在一行:
x = rand(Truncated(Normal(0, 1), 0, 1), 100)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
397 次 |
| 最近记录: |