Skip to content
Prev 346027 / 398502 Next

Generate random numbers under constrain

Hello! I am relatively new using R, but this is my contribution to the
answer. How about using a Monte-Carlo method. Generate m numbers in the
support [0,1], where m>n. Then constrain by constructing a loop that takes
every one of the elements in the m sized vector and select the ones that
sum up to one. If it is very uncommon to sum up to one, given the
distribution that you use to generate the random numbers, you can construct
a loop that generates as many random numbers as you need and then follow
the steps
1.generate
2.select

until you find a total of n number.
from [0,1]
?Best regards,?