function index=chooserandom(prob)

%Select random based on probabilities

u=rand(1,1);

nv=length(prob); %Do we need this?
i=1;
S=prob(i);
while S<u && i<nv
    i=i+1;
    S=S+prob(i);        
end

index=i;