Skip to content
Prev 346034 / 398502 Next

Generate random numbers under constrain

How about generating the uniform numbers sequentially and keep the running sum of all the previous numbers. At each step check if the newly generated random number plus the running sum > 1 discard the number and generate a new one, repeat the condition check. If the new number plus old sum < 1 accept the number and repeat the step. Until you got n numbers. 

Mikhail