I would like to generate random words from ascii codes. 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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.