vendredi 16 septembre 2016

Generate random strings of fixed length from given characters with equal occurance

I want to generate random strings from a list of characters C (e.g. C = ['A', 'B', 'C', 'D']). This random string shall have length N (e.g. N = 32). Every character should occur equally often - in that example 8 times.

How can I implement that each character occurs equally often in here:

''.join(random.choice(C) for i in range(N))

Or is there a better way?




Aucun commentaire:

Enregistrer un commentaire