> I need to generate a password..It has to be an 8 digit number and it
> has to be random

I assume you mean a string representing an 8 digit random number?
If so...

> 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?

Eventually it will generate a single digit number if its truly random!

But when you convert it to a string (see assumption above!) you can
pad it with zeros


passString = "%08d" % random.randrange(0,99999999)

Is that what you want?

Alan G.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to