In article <3CE2D4E5.9060500 / linuxmail.org>, Bob X <bobx / linuxmail.org> 
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()

def generatePassword(minlen=5, maxlen=10)
   chars = ("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a
   pwlen = rand(max - min) + min + 1
   (1..pwlen).to_a.collect {|x| chars[rand(chars.length)] }.join
end

puts generatePassword