简体   繁体   English

使用python的随机词生成器

[英]Random word generator using python

I would like to generate random words from ascii codes. 我想从ASCII码生成随机单词。 I have tried like that: 我已经尝试过:

 import random

 liste = [random.randint(33, 127) for i in range(8)]
 osman=', '.join(str(x) for x in liste)
 a=bytes.fromhex(hex(liste[0])[2:]).decode()
 b=bytes.fromhex(hex(liste[1])[2:]).decode()
 c=bytes.fromhex(hex(liste[2])[2:]).decode()
 d=bytes.fromhex(hex(liste[3])[2:]).decode()
 e=bytes.fromhex(hex(liste[4])[2:]).decode()
 f=bytes.fromhex(hex(liste[5])[2:]).decode()
 g=bytes.fromhex(hex(liste[6])[2:]).decode()
 h=bytes.fromhex(hex(liste[7])[2:]).decode()

 print(a,b,c,d,e,f,g,h,sep="")

Is there an easier way and how can i develop for more words? 有没有更简单的方法,我如何开发更多的单词?

I have found that exactly I want to do.Thanks to Vasilis G. 我发现我确实想做。感谢VasilisG。

import random
i=0
k=""
while i<100:
    i+=1    
    liste = [random.randint(97, 122) for i in range(8)]
    osman=''.join(chr(x) for x in liste)
    k+=osman+" "
print(k)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM