perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruce Johnson" <john...@Pharmacy.Arizona.EDU>
Subject Re: random token re-used in subsequent requests
Date Mon, 16 May 2016 18:03:11 GMT

> On May 16, 2016, at 10:15 AM, André Warnier (tomcat) <aw@ice-sa.com> wrote:
> 
> 
> join "", map +(0..9,"a".."z","A".."Z")[rand(10+26*2)], 1..32 ;
> 
> looks at first sight to me like quite inefficient and probably likely to generate the
same string regularly, even if it does not look that way.
> (The only variable there is rand(), and it can only return values between 0 and 62).

The  function is meant to map a random element from the 62-element-long  array (0..9,"a".."z","A".."Z”)
(hence a rand() call to generate a number from 0 and 62), 32 times, and join them into a string.


Although I think that should really be rand(9+26*2) to properly generate array indices for
the entire array and no more. With a number between 0 and 62 (63 numbers) and a 62-element
array, you’ll be retrieving nulls from the array 1/62 calls,  but all that means is that
the string is one char shorter for each time '62’ comes up...

So long as rand is properly seeded, you should not get repeats, at least not frequently enough
to ever notice, I’d think. 

This is textbook Perl, as in I’m pretty sure it’s out of one of Larry Wall’s books;
I use it to generate random strings for cookies. 

If it’s properly seeded in the original code, it should either work or not work on all five
servers. Not working on one out of the five makes me think maybe there’s some sort of weird
caching issue.

-- 
Bruce Johnson
University of Arizona
College of Pharmacy
Information Technology Group

Institutions do not have opinions, merely customs

Mime
View raw message