Random passwords generation (Python vs Perl) =)

Stargaming stargaming at gmail.com
Mon Jan 29 16:25:26 CET 2007


NoName schrieb:
> Perl:
> @char=("A".."Z","a".."z",0..9);
> do{print join("", at char[map{rand @char}(1..8)])}while(<>);
> 
> !!generate passwords untill U press ctrl-z
> 
> 
> 
> Python (from CookBook):
> 
> from random import choice
> import string
> print ''.join([choice(string.letters+string.digits) for i in 
> range(1,8)])
> 
> !!generate password once :(
> 
> who can write this smaller or without 'import'?
> 

If you really want a hack, here it is:

while 1:print 
''.join(__import__('random').choice(__import__('string').letters+'1234567890') 
for x in xrange(8)),;n=raw_input()

This is a one-liner (though mail transmission may split it up), no 
import statements. If someone can come up with an even smaller version, 
feel free to post. :)

-- Stargaming



More information about the Python-list mailing list