in reply to Random String Generator

Ugh. I had to deparse it to see the forest for all those parens (hacker's version is even worse). What purpose does reversing an already random string serve? It doesn't contribute any randomness. Not to mention you're calling reverse in list context but with only one parameter, so effectively it's not even doing anything at all.
#!/usr/bin/perl -w use strict; use English '-no_match_vars'; my $sum = 0; $sum += $_ for localtime; print substr(crypt($sum * $UID / $EGID, rand $PID), 2, 9);
Generally it seems like you're just trying to throw as much "random stuff" into the pile as possible - but it's not really contributing anything. For high quality random data rendered as a typeable string I'd just dump a bunch of bytes from /dev/urandom and uu- or base64-encode them.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re:x2 Random String Generator (It's the Knuth!)
by grinder (Bishop) on Jun 04, 2003 at 16:00 UTC
    Generally it seems like you're just trying to throw as much "random stuff" into the pile as possible - but it's not really contributing anything.

    Indeed. This reminds me of Donald Knuth's Algorithm K, the "super-random" number generator. He develops an complex 13-stage algorithm that is "intended to be so complicated that a person reading a listing of it without explanatory comments wouldn't know what the program was doing".

    Sadly, the first time it was iterated, using the function's output as its input, it immediately converged on a single value. Trying other initial values produced the same result. Reflecting upon this, Knuth wrote:

    "...random numbers should not be generated with a method chosen at random. Some theory should be used." (Seminumerical Algorithms, Chapter 3.1).

    _____________________________________________
    Come to YAPC::Europe 2003 in Paris, 23-25 July 2003.

Re: Re: Random String Generator
by nimdokk (Vicar) on Jun 04, 2003 at 11:02 UTC
    The reverse() is a holdover from an earlier incarnation where a string and seed were fed at the commandline. I noted that the seed became the first character in the string, which is why I reveresed it. There is much less of a need for that now.

    "Ex libris un peut de tout"