samples=1000; n=50; P.a=.5; P.b=.9 par(mfrow=c(1,2)) y.a=c(); y.b=c(); for (sample in 1:samples){ #y=rgamma(n,4,1/5); y=rnorm(n,0,1); y=sort(y); y.a=c(y.a,y[P.a*n]); y.b=c(y.b,y[P.b*n]); } hist(y.a) ; hist(y.b)