+ 2
Can a random combination of characters be generated in Python? Someone asked me but I don't know myself.
5 Réponses
+ 7
Lakshya,
i took the sample from FF9900 and used "choices" instead of "choice". see the comments in the code:
# Created by FF9900
from random import choices, choice
from string import ascii_uppercase as UCASE
for j in range(20):
print(''.join(choice(UCASE) for i in range(5)))
# edited by lothar
# generate one string with k characters
print("".join(choices(UCASE,k=5)))
# generate multiple strings with k characters:
for j in range(20):
print("".join(choices(UCASE,k=5)))
+ 2
Sure
0
FF9900 Do you mind if I save that code? I won’t make it public, but I haven’t seen that library before and I want to reference that when I have a bit more time