Distribution of uniform RVs under sum constraint Suppose I generate $x_1,x_2,x_3,x_4$ through the following procedure:


*

*Sample $x_1,x_2,x_3 \sim \text{unif}(0, 1)$, iid  

*While $x_1+x_2+x_3 > 1$, resample them all

*Let $x_4 = 1 - x_1 - x_2 - x_3$
What is the distribution of the $x_1,x_2,x_3,$ and $x_4$ we end up with afterwards? I empirically found that they all seem to follow the same distribution, but can't figure out how to derive this distribution analytically. 
 A: The answer is:that's not true. 
it is look like 


*

*generate $(X_1,X_2,X_3)$ such that $S=X_1+X_2+X_3 \leq 1$

*$X_4=(1-S)$
or on the other hands  $X_4= (1-S|S<1) $. 
now we want to find a conditional distribution $(1-S|S<1)$.
$S=X_1+X_2+X_3$ and according to https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution
\begin{eqnarray}
  f_S(a)=\left\{
  \begin{array}{cc}
  \frac{1}{2} a^2 & 0\leq a <1 \\
  \frac{1}{2}(-2a^2+6a-3) & 1\leq a<2 \\
  \frac{1}{2} (a-3)^2 & 2\leq a<3
  \end{array}
  \right.
  \end{eqnarray}
so $P(S\leq 1)=\int_{0}^{1} \frac{1}{2} a^2 da=\frac{1}{6}$ 
and
$P( 1-x \leq S\leq 1)=\int_{1-x}^{1} \frac{1}{2} a^2 da$
$=\frac{1}{6} a^3|_{1-x}^{1}=\frac{1}{6}(1-(1-x)^3)$
so $F_{X_4}(x)=P(X_4\leq x)=P(1-S\leq x|S<1)=P(S\geq 1-x|S\leq 1)$
$=\frac{P( 1-x \leq S\leq 1)}{P(S\leq 1)}=1-(1-x)^3 $ $,x<1$
its not look like uniform distribution and $f_{X_4}(x)=3(1-x)^2$ .($beta(1,3)$ distribution)
a simple simulation  confirms that the $X_4$ does not follow uniform distribution:
x4<-c()
count<-1
simu<-6*1000
for(i in 1:simu){
              x<-runif(3)
              s<-sum(x) 
              if(s<1) {x4[count]<-1-s;count<-count+1}
}
plot(density(x4),type="l",xlim=c(0,1))
 > ks.test(x4,runif(length(x4)))

    Two-sample Kolmogorov-Smirnov test

data:  x4 and runif(length(x4))
D = 0.37026, p-value < 2.2e-16
alternative hypothesis: two-sided


it's simple to check $1-S|S>1$ does not have uniform distribution.
