Is there any difference between rand(n,1) and unifrnd(0, 1, n, 1)?
이전 댓글 표시
Is there any difference between
rand(n,1)
and
unifrnd(0, 1, n, 1)?
채택된 답변
추가 답변 (1개)
Anne van Rossum
2016년 6월 29일
There is less error checking in rand, which can be at times preferred... For example, if you need to generated random numbers between a and b, and it doesn't matter if a > b.
a = 5
b = -5
Then:
a+(b-a)*rand(1,400)
But you'll need to make sure a and b are properly ordered for unifrnd:
if (b < a)
[a, b] = deal(b, a);
end
unifrnd(a,b,1,400)
Or else your result will be a vector of NaNs.
카테고리
도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!