develooper Front page | perl.beginners | Postings from August 2009

Re: two questions

Thread Previous | Thread Next
From:
Chas. Owens
Date:
August 5, 2009 11:06
Subject:
Re: two questions
Message ID:
58ce48dc0908051106t3a3eae4fn6c7724b95ce78620@mail.gmail.com
On Wed, Aug 5, 2009 at 11:06, John W. Krahn<jwkrahn@shaw.ca> wrote:
> Chas. Owens wrote:
>>
>> On Wed, Aug 5, 2009 at 10:01, John W. Krahn<jwkrahn@shaw.ca> wrote:
>> snip
>>>>
>>>> If you want to use the string in a URL then it cannot be truly random,
>>>> because
>>>> not every character can appear in a URL.
>>>
>>> That does not make sense.
>>
>> snip
>>
>> I believe he/she meant that not every character is allowed in a regex,
>
> But... every character *is* allowed in a regex.

Whoops typo, that should have been URL not regex.

>
>> so you can't just generate a random string made up of any characters.
>> You must use a restricted character set.
>
> Yes, but, you can use any number of encoding schemes to translate "any
> character" to an "unrestricted character".
snip

Yes, but why bother for a random string?  Just create one that has the
right number of characters of the restricted set:

my $random = join '', map { $set[rand @set] } 1 .. 20;

or use a random number in base 16 or 64.



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About