function [ x ] = ranExp( dim,lambda )
%ranExp: random vector in hypercube with exponential density

    % column vector with 'dim' random numbers (uniform from [0,1])
    y = rand(dim,1);  
    % transform (elementwise) to random numbers in [exp(-lambda),1]
    y =  exp(-lambda) + (1-exp(-lambda))*y;   
    % this gives us random numbers with exponential density
    x = -log(y)/lambda;   % note this is elementwise again
    
end

