How to pick random number?

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 个评论

Thanks a lot Azzi. By the way, what is the probability to chose one of these numbers?
Thank you Azzi Abdelmalek, you help me too... God Bless

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Language Fundamentals 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by