Does anybody know how to generate two random numbers which sum is less than one?
I found only topics describing how to generate 2 random numbers which add up to 1 (trough normalization)
Does anybody know how to generate two random numbers which sum is less than one?
I found only topics describing how to generate 2 random numbers which add up to 1 (trough normalization)
Assuming you don't care too much about the distribution:
x = rand(2,1);
if sum(x)>1
x=x/2;
end
Modifying normKrumpe's answer, I'd suggest
r1
less than (or <=?) the sum.r2 = sum-r1
.