[Tutor] Generate 8 digit random number

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Fri Aug 26 16:12:31 CEST 2005


Is "0" a valid digit for your password ?

If the answer is "YES" then, remember that the "0" at the left of a
number are juste removed ! In that case, try writing your password with :

"%08d" % password

Pierre

Alberto Troiano a écrit :
> Hi everyone
> 
> I need to generate a password..It has to be an 8 digit number and it has to 
> be random
> 
> The code I've been trying is the following:
> 
> 
> import random
> random.randrange(00000000,99999999)
> 
> The code works but sometimes it picks a number with 7 digits. Is there any 
> way that I can tell him to select always a random number with 8 digits?
> 
> Thanks in advanced
> 
> Alberto
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68


More information about the Tutor mailing list