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

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

 采纳的回答

sakeki
sakeki 2022-11-17

0 个投票

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

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 随机数生成 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!