python产生随机字符串

def GenerateRandomString(len, basechars = []):  
     if (basechars == []):  
         x = range(ord('a'), ord('z') + 1)  
         x.extend(range(ord('A'), ord('Z') + 1))  
         x.extend(range(ord('0'), ord('9') + 1))  
         basechars = [chr(i) for i in x]  
         ret = ''  
         for i in range(len):  
            ret += random.choice(basechars)  
         return ret  

 

posted @ 2018-04-26 15:55  天空是我喜欢的颜色  阅读(220)  评论(0编辑  收藏  举报