How to pick random number?

조회 수: 3 (최근 30일)
Rose
Rose 2013년 10월 2일
댓글: Dennis M 2021년 2월 27일
Hi, Please forgive me if I am asking a basic question. I want to pick random number from the set {2,3}. It should either pick 2 or 3 randomly. I have been looking at these functions called 'rand', 'randi', 'randperm' etc., but i couldn't figure out how to use them for my problem. Any help would be appreciated.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 2일
편집: Azzi Abdelmalek 2013년 10월 2일
randi([2 3])
%or
v=[2 3];
v(randi(2))
  댓글 수: 3
Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 3일
1/2
Dennis M
Dennis M 2021년 2월 27일
Thank you Azzi Abdelmalek, you help me too... God Bless

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by