필터 지우기
필터 지우기

Matlab equivalent of rand() in C++

조회 수: 3 (최근 30일)
Rishi Balasubramanian
Rishi Balasubramanian 2021년 4월 17일
댓글: Rishi Balasubramanian 2021년 4월 17일
Hello,
I am trying to adapt a C++ code to my Matlab project.
In C++ there is this line
random4 = rand() % item // Here the % is modulo in C++
So random is the range of values 'rand' modulo by variable 'item'.
How do I implement this in Matlab. Since I am looking for targeted platform and efficiency, I cannot call the Cpp file in matlab. I am looking for a matlab adaptation.
Any help or suggestions offered are much appreciated. Thank you in advance...
  댓글 수: 3
Walter Roberson
Walter Roberson 2021년 4월 17일
no. randi(6) would be 1 to 6, but random integer mod 6 would be 0 to 5. You can randi([0 5])
Rishi Balasubramanian
Rishi Balasubramanian 2021년 4월 17일
Ah, wow, that would have been a crucial error. Thanks for pointing it out man.

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

채택된 답변

Bruno Luong
Bruno Luong 2021년 4월 17일
편집: Bruno Luong 2021년 4월 17일
random4 = randi(item)-1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by