使用Python的随机单词生成器

2024-09-28 21:43:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从ascii码生成随机字。 我已经试过了:

 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="")

有没有一种更简单的方法?我怎样才能发展出更多的单词?在


Tags: inimportforbytesasciirangerandomjoin
1条回答
网友
1楼 · 发布于 2024-09-28 21:43:31

我发现这正是我想要的好的。谢谢给瓦西里斯G

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)

相关问题 更多 >