vardef exponential_pdf(expr x, lambda) =
if x < 0: 0 else: lambda * mexp(-256x * lambda) fi
enddef;
path E;
E = ((0, exponential_pdf(0, 1)) for x=1 upto 6: .. (x, exponential_pdf(x, 1)) endfor)
xscaled scale yscaled 1.8N;
draw E withcolor 1/2 red;
string p;
for i=1 upto 5:
p := decimal (bucket[i] / N / N);
label.bot("\tiny " & p, ((i-1/2) * scale, -10));
endfor
pair a, b;
a = point 1/4 of E shifted (2,3);
b = point 1/4 of E shifted (20, 30);
draw a -- b withpen pencircle scaled 1/4;
label.urt("$\lambda e^{-\lambda x}$", b);
label.llft("\large\textsf{Histogram of exponential deviates}", urcorner currentpicture);