Random strings in Python 2.6 (Is this OK?)

前端 未结 5 1715
独厮守ぢ
独厮守ぢ 2020-12-12 12:54

I\'ve been trying to find a more pythonic way of generating random string in python that can scale as well. Typically, I see something similar to

\'\'.join(r         


        
5条回答
  •  旧巷少年郎
    2020-12-12 13:22

    Regarding the last example, the following fix to make sure the line is even length, whatever the junk_len value:

    junk_len = 1024
    junk =  (("%%0%dX" % (junk_len * 2)) % random.getrandbits(junk_len * 8)).decode("hex")
    

提交回复
热议问题