help random numbers generator
조회 수: 1 (최근 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!