tweaking random number

Chris Angelico rosuav at gmail.com
Wed May 9 03:44:00 EDT 2012


On Wed, May 9, 2012 at 5:01 PM, Nikhil Verma <varma.nikhil22 at gmail.com> wrote:
> Hi All
>
> I want to generate a random number of 8 digits which involve 3 number and 5
> digits.

(That's 3 digits and 5 letters) Pretty easy. Do you want to
distinguish between uppercase and lowercase letters?

Your current random_number function (btw, I wouldn't call it "number"
as it isn't one) is most of one possible solution. Divide it into two
parts, one part that generates the digits and another part that
generates the letters. Your 'characters' template would thus be
different for the two parts.

There are other solutions, which involve the generation of less random
numbers, but your way will work.

ChrisA



More information about the Python-list mailing list