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.

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 2 de Oct. de 2013
Editada: Azzi Abdelmalek el 2 de Oct. de 2013

3 votos

randi([2 3])
%or
v=[2 3];
v(randi(2))

3 comentarios

Rose
Rose el 3 de Oct. de 2013
Thanks a lot Azzi. By the way, what is the probability to chose one of these numbers?
Azzi Abdelmalek
Azzi Abdelmalek el 3 de Oct. de 2013
1/2
Dennis M
Dennis M el 27 de Feb. de 2021
Thank you Azzi Abdelmalek, you help me too... God Bless

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 2 de Oct. de 2013

Comentada:

el 27 de Feb. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by