in reply to Re: Randomizing Unique ID?
in thread Randomizing Unique ID?

Nice solution. Downsides: Implementing these three changes, I'd go with something like:
BEGIN { my @source = ('A'..'Z', 'a'..'z', '0'..'9'); sub generate_random_password { my $id = ""; for (1..18) { $id .= $source[rand @source]; } $id; } }
For so-called "pronounceable" passwords, try Crypt::RandPasswd. Looks nice, and based on a government standard.

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: RE: Re: Randomizing Unique ID?
by BlaisePascal (Monk) on Aug 10, 2000 at 22:52 UTC
    About your downsides...

    1) Yup, I can see capturing the 62-element in a closure instead of re-creating it. I didn't think of that when I was coding off the top of my head.

    2) Nice catch

    3) Oops... I missed that. I looked in the library to verify the result of rand() and it said it returns a float, not an int. But I guess the [ takes care of that...

    Since this is supposed to be a "UniqueID" and not a password, using "pronounceable" passwords are probably not necessary.

    Why put it in a BEGIN block? Doesn't seem necessary to me.