在限制条件下生成随机数的问题。

求教,需要生成系列随机数,要求生成3个随机数,总和为18,且要求每个随机数的范围在[0,12]内,该如何生成?谢谢

 Respuesta aceptada

sakeki
sakeki el 17 de Nov. de 2022

0 votos

while(1)
suiji=randi([0,12],1,3);
if sum(suiji)==18
break;
end
end

Más respuestas (0)

Categorías

Más información sobre 随机数生成 en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 17 de Nov. de 2022

Respondida:

el 17 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!