On Wed, 15 May 2002 17:36:37 -0400, Bob X wrote:

> Python has a whrandom or something like that and I would like to create
>    a random password generator at work in Ruby instead. The Python goes
> something like this:
> 
> import string
> import whrandom
> 
> def generatePassword(minlen=5, maxlen=10):
> 	chars = string.letters + string.digits passwd = ""
> 	
> 	# determine password size
> 	passwd_size = whrandom.randint(minlen, maxlen)
> 
> 	for x in range(passwd_size):
> 		# choose a random alpha-numeric character passwd +=
> 		whrandom.choice(chars)
> 
> 	return passwd
> 
> print generatePassword()


well i'm not very good at ruby, but i was thinking of something like
-------------------------------------------------------------------
#!/usr/bin/ruby

def generatePassword(minlen = 5, maxlen = 10)

  passwd_len = (rand(maxlen - minlen) + minlen)
  passwd = ""

  while (passwd.length < passwd_len) do
    n = rand(74) + 48;
    passwd << n.chr if (n < 58 || n > 64 && n < 91 || n > 96)
  end

  password

end

puts generatePassword()
-----------------------------------------------
is there a more straight-forward way of doing it?

love,
pizza

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com