Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Not understanding some code

$
0
0
I was trying to come up with a random collection of characters and upon searching to see if such a list already existed I found this link:
http://stackoverflow.com/questions/2257441/python-random-string-generation-with-upper-case-letters-and-digits

Which is all fine and good but when I tried it I set it up a little different. I set it up as such:
import random, string

def idgen(size=8, chars=string.ascii_letters + string.digits):
    newpass = ''
    for x in range(size):
        newpass.join(random.choice(chars))
    return newpass

print(idgen())



My code gives me no output but the one linked does. Am I not understanding something about the code and strings in general?

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>