Add Perl port, cribbed mostly from Python.

I'm not convinced I've faithfully duplicated the intended randomization, but the output looks a whole lot like that of the Python and C implementations.