Based on DhruvPathak's straight forward answer with creating a simple random string of characters, I have two additions: ① a non-uniform distribution and ② a random translation to prevent prediction of the frequency of the letters:
translation = range(26)
random.shuffle(translation) # ②
random_string = ''.join(chr(
translation[random.randint(0, random.randint(1, 25))] + ord('a')) # ①
for _dummy in range(1000))
The non-uniformly distribution is achieved by using randint(randint(…))
which basically prefers the lower numbers as output.
In a first try I got this translation
list:
[5, 18, 22, 16, 3, 20, 2, 4, 19, 24, 9, 21, 12, 15, 7, 0, 25, 11, 14, 17, 10, 8, 13, 6, 1, 23]
And a count of the characters in the resulting random_string
(done by f = [ 0 ] * 25
, for c in random_string: f[ord(c) - ord('a')] += 1
, zip(*reversed(sorted(zip(f, range(26)))))[1]
) gave this list:
(18, 5, 22, 16, 3, 20, 2, 4, 19, 24, 12, 21, 15, 9, 0, 7, 25, 14, 17, 10, 11, 13, 8, 1, 23, 6)
So, the outcome matches the expectation pretty well.