Borrar filtros
Borrar filtros

How to add parameters to randi inputs

2 visualizaciones (últimos 30 días)
Christian Armistead
Christian Armistead el 10 de Dic. de 2017
Respondida: Roger Stafford el 10 de Dic. de 2017
I need to use randi to produce a string of random numbers, the string should either end when the last digit of the last number is 9 or the the output reaches 15 numbers. Also the numbers can only be between 1 and 999. I know how to use the randi function however I don't know how to use it with all of these parameters.

Respuestas (1)

Roger Stafford
Roger Stafford el 10 de Dic. de 2017
v = randi(999,15,1);
for k = 1:15
if mod(v(k),10) == 9
v = v(1:k);
break;
end
end
% Vector v is the desired result

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by