MATLAB: HOW TO USE RANDOM

random number generator

there are two formulas
K1 + K2 + K3 =1 (1)
K1 > K2 > K3 (2)
I need 100 random combinations of the K1, K2 and K3
how can I do in the MATLAB

Best Answer

N = 100 ;
k = linspace(0,1,N) ;
[K1,K2,K3] = ndgrid(k,k,k) ;
thesum = K1+K2+K3 ;
idx = thesum==1 ;
K1 = K1(idx) ; K2 = K2(idx) ; K3 = K3(idx) ;
K = [K1 K2 K3] ;
idx = K1<K2 & K2<K3 ;
iwant = K(idx,:) ;