help random numbers generator
7 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I'd like to know how to generate a set of random numbers with normal distribution (randn) belonging to a range defined by me.
To make it easier:
I want to generate 10 random numbers between [-0.5 0.5] using randn.
Thanks for your attention
0 个评论
采纳的回答
Jeff Miller
2020-5-25
Good. Here it is as an 'official' answer:
pd = makedist('Normal');
t = truncate(pd,-0.5,0.5);
r = random(t,10,1);
0 个评论
更多回答(1 个)
KSSV
2020-5-23
a = -0.5 ;
b = 0.5 ;
N = 10 ;
r = (b-a).*randn(N,1) + a;
7 个评论
Jeff Miller
2020-5-25
If that would work, then I guess this is what you are after:
pd = makedist('Normal');
t = truncate(pd,-0.5,0.5);
r = random(t,10,1);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!