clear  
close
N=input('N = ');
lambda = input('lambda = ')
r=rand(N,1);
figure(1)
[nr,xr]=hist(r,10);bar(xr,nr/N,0.9);
x = - (1/lambda)*log(1-r);
figure(2)
[nx,xx]=hist(x,10);bar(xx,nx/N,0.9);
hold on 
tmax = max(x);
t=linspace(0,tmax,N); ft = lambda*exp(-lambda*t); plot(t,ft)
figure(3)
plot(x,r,'*')