samedi 8 septembre 2018

Generate Random String with three alphabets of different lengths in Python

I want to create a random string that contains three alphabets of different lengths. for example: if a = 2, b = 5, c=1 then strings are:

  • aabbbbbc
  • ababbbcb
  • abcabbbb

and so on....

However, I am capable of achieving such kind of functionality using python random.choice() function.

>>> print(''.join(choice('a'+'b'+'c') for i in range(5)))
aacaa




Aucun commentaire:

Enregistrer un commentaire