function [MYANS] = myNRandPlusEqualOne(N)
%param N 表示要生成多少个随机数
%return MYANS--N*1
%function 函数是为了生成N个加起来和为1的向量
%CopyRight NUST CS726 Jun.H(111060881)
tempANS = zeros(N, 1);
res = 1;
for R=1:N-1
t = rand();
if t<0 || t>1
error('rand function create a value is not in [0, 1]');
end
tempANS(R, 1) = res*t;
res = res*(1-t);
end
tempANS(N, 1) = res;
MYANS = tempANS;
%param N 表示要生成多少个随机数
%return MYANS--N*1
%function 函数是为了生成N个加起来和为1的向量
%CopyRight NUST CS726 Jun.H(111060881)
tempANS = zeros(N, 1);
res = 1;
for R=1:N-1
t = rand();
if t<0 || t>1
error('rand function create a value is not in [0, 1]');
end
tempANS(R, 1) = res*t;
res = res*(1-t);
end
tempANS(N, 1) = res;
MYANS = tempANS;