[Tutor] Generate 8 digit random number
Alberto Troiano
albertito_g at hotmail.com
Fri Aug 26 16:31:21 CEST 2005
Hey ALL
The code Kent sent might work ok but I didn't see it because of what Pierre
said about the left 0's
I think I will go with Pietro's approach. I think is neater and shorter than
the randrange approach
Thanks to all that helped
Best Regards
Alberto
>From: Kent Johnson <kent37 at tds.net>
>CC: tutor at python.org
>Subject: Re: [Tutor] Generate 8 digit random number
>Date: Fri, 26 Aug 2005 10:16:37 -0400
>
>Alberto Troiano wrote:
> > Hi Kent
> >
> > Nope...
> > Not working....I'm still getting 7 even 6 digits number
>
>Are you sure? It works for me:
> >>> import random
> >>> random.randrange(10000000,99999999)
>42247129
> >>> for i in range(1000):
> ... x = random.randrange(10000000,99999999)
> ... if len(str(x)) < 8:
> ... print x
> ...
> >>> (prints nothing - they are all 8 digits)
>
>Kent
> >
> > Any other idea?
> >
> > Thanks
> >
> > Alberto
> >
> >> From: Kent Johnson <kent37 at tds.net>
> >> CC: tutor at python.org
> >> Subject: Re: [Tutor] Generate 8 digit random number
> >> Date: Fri, 26 Aug 2005 10:00:50 -0400
> >>
> >> Alberto Troiano wrote:
> >> > 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?
> >>
> >> random.randrange(10000000,99999999) ??
> >>
> >> Kent
> >>
> >> _______________________________________________
> >> Tutor maillist - Tutor at python.org
> >> http://mail.python.org/mailman/listinfo/tutor
> >
> >
> >
> >
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list