Home > OS >  I only have emoticons and not text
I only have emoticons and not text

Time:12-13

I want to make a generator of random letters, but instead of letters I only have emoticons. Here is the code.

import random
from random import randint

#random number of characters
sym=random.randint(100,500)
num=0
bn=[]

while num < sym :
    rb=random.randint(0,1)
    bn.append(rb)
    num =1 
print(bn) #for check

bn=str(''.join(map(str, bn)))



def decode(lst):
    txt= ''.join(map(lambda x: chr(int(x,2)), lst))
    print("txt=",txt)


decode(bn)

The code should be letters or even numbers, but don't smile! I tried all the ways I could think of, but the result is the same

CodePudding user response:

Here how to use random.choice to pick a random string.

import random

sym=random.randint(100,500)
alphabet = "abcdefghijklmnopqrstuvwyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"

bn=[]
for _ in range(sym):
    bn.append(random.choice(alphabet))
bn = ''.join(bn)
print(bn)
  • Related