function [Y Ind Pond]=unifsuprnd3(tri,X,Nsim);
P=size(X,2);
%etape 1 simulation de Nsim points uniformement sur le supports
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%1-1 calcul du volume
Nt=size(tri,1);
Pt=size(tri,2);
Vt=zeros(Nt,1);
for i=1:Nt
    Vt(i)=volumesimplexe2(X(tri(i,:),:));
end
Voltot=sum(Vt);
Vt=Vt/Voltot;
Wt=zeros(Nt,1);
for i=1:Nt
    Wt(i)=sum(Vt(1:i));
end
clear Vt 

%1-2 tire aléatoirement un simplexe
%U1=unifrnd(0,1,Nsim,1);
U1=rand(Nsim,1);
Ind=zeros(Nsim,1);
for i=1:Nsim
    if U1(i)<Wt(1) 
        Ind(i)=1;
    else
        indi=find(Wt>=U1(i));
        Ind(i)=indi(1);
    end
end

%1-3 tire les poids
Pond=zeros(Nsim,Pt);
U=ones(Nsim,Pt);
%U(:,2:Pt)=unifrnd(0,1,Nsim,Pt-1);
U(:,2:Pt)=rand(Nsim,Pt-1);
U=sort(U,2);
Pond(:,1)=U(:,1);
for j=2:Pt
    Pond(:,j)=U(:,j)-U(:,j-1);
end

%1-4 tire les points
Y=zeros(Nsim,P);
for i=1:Nsim
    Y(i,:)=Pond(i,:)* X(tri(Ind(i),:),:);
end

