Get real random numbers from Perl's rand()

On Stackoverflow, someone asks how to get 100 random numbers without a loop. It's one of those dumb homework problems that tries to forbid only one of many things instead of specifying the technique it really wants the student to practice. In Perl land, that leaves the door open for the sick and twisted minds of people such as Tom Christiansen and Sinan Ünür. I wonder if the teacher would even understand their solutions, much less accept them.

Many of the answers went to great pains to avoid certain Perl keywords while still creating loops. Some people debated if map is a loop. Some people used recursion, forgetting that every time you recurse in Perl, God kills a kitten. Maybe someday people will realize that recursion in Perl isn't the same kung fu they see in other languages. Perl actually must recurse because it has no way of knowing if it's going to call the same function definition.

Most of the solutions used Perl's built-in rand, which I think ignores half of the problem, the random numbers themselves. I use rand too, but I replace its definition to use the web service to get lists of random numbers generated from atmospheric noise. Not only that, but I change rand in very sick and twisted ways, adding a list context.

Leave a comment

About brian d foy

user-pic I'm the author of Mastering Perl, and the co-author of Learning Perl (6th Edition), Intermediate Perl, Programming Perl (4th Edition) and Effective Perl Programming (2nd Edition).