[Tutor] Random Numbers
Jorge Godoy
godoy@metalab.unc.edu
Thu Jul 24 12:26:04 2003
Michie DeBerry <phate@rockriver.net> writes:
> Hello,
> Allow me to start by introducing myself. My name is Michie, and I am currently
> reading Sam's Teach Yourself Python in 24 Hours. I was wondering if there is
> anyway to create a random number in Python. I am currently writting a program
> to create a password for you. It will have more features later on, but for
> right now, that is all I need it to do. Any suggestions as how to go about
> creating a random number x number of times to get a-z or 0-9 from a list?
I did that when I created a graphical frontend to create crypt() and
MD5 hashes of passwords.
This is the relevant part:
----------------------------------------------------------------------
#!/usr/bin/env python
import crypt
import string
import random
from Crypto.Hash import MD5
(...)
def ConvertPassword(self, event):
characters = ''.join([string.ascii_letters, string.digits, './'])
salt = ''.join([random.choice(characters), random.choice(characters)])
original_pwd = self.BxPasswd.GetValue()
md5 = MD5.new(original_pwd).hexdigest()
crypted = crypt.crypt(original_pwd, salt)
self.TxtMD5.SetValue(md5)
self.TxtCrypt.SetValue(crypted)
----------------------------------------------------------------------
See you,
--
Godoy. <godoy@metalab.unc.edu>