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

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

 Réponse acceptée

sakeki
sakeki le 17 Nov 2022

0 votes

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

Plus de réponses (0)

Catégories

En savoir plus sur 随机数生成 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!