+ 2

Can a random combination of characters be generated in Python? Someone asked me but I don't know myself.

21st Feb 2022, 2:04 PM
Lakshya
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)))
21st Feb 2022, 3:35 PM
Lothar
Lothar - avatar
+ 2
Sure
21st Feb 2022, 3:14 PM
Alan Ambrose
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
23rd Feb 2022, 1:30 PM
Andrew Johnson
Andrew Johnson - avatar