How can I generate random varaible from 0 to 1 without including 0?

조회 수: 20 (최근 30일)
Mira le
Mira le 2021년 9월 12일
댓글: Rik 2021년 9월 12일
Hello every one,
I want to generate random values between 0 and 1, but not 0
I don t want to generate 0 as a random value.
thank you

채택된 답변

Dave B
Dave B 2021년 9월 12일
The rand function generates randum numbers between 0 and 1, not including 0 or 1:
rand
ans = 0.2257
rand(1,5)
ans = 1×5
0.6583 0.2099 0.4393 0.8476 0.4583
rand(3)
ans = 3×3
0.2514 0.5840 0.3004 0.1508 0.9781 0.8052 0.5088 0.2080 0.5720
  댓글 수: 1
Rik
Rik 2021년 9월 12일
rng(1);%make the output of rand() repeatable
R=min(rand(1e7,1));
[0 R 1]
ans = 1×3
0 0.0000 1.0000
Although sometimes the returned value might be displayed as 0.
R
R = 3.0078e-07

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by