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

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

 Accepted Answer

sakeki
sakeki on 17 Nov 2022

0 votes

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

More Answers (0)

Categories

Find more on 随机数生成 in Help Center and File Exchange

Tags

Asked:

on 17 Nov 2022

Answered:

on 17 Nov 2022

Community Treasure Hunt

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

Start Hunting!