I decided to crack the solution based on user166390 suggestion. The frequencies you see relate to English taken from Wikipedia. By executing the program several times and just looking at the results, they look pretty gaming for me. As a rule, I can find a few four- or five-letter words, and I'm not even very good at playing! Anyway, here is the code:
#!/usr/bin/env python from random import random from bisect import bisect_left letters = [c for c in "abcdefghijklmnopqrstuvwxyz"] frequencies = [8.167, 1.492, 2.782, 4.253, 12.702, 2.228, 2.015, 6.094, 6.966, 0.153, 0.772, 4.025, 2.406, 6.749, 7.507, 1.929, 0.095, 5.987, 6.327, 9.056, 2.758, 0.978, 2.360, 0.150, 1.974, 0.074] cumulative_frequencies = [sum(frequencies[0:i+1]) for i in xrange(len(frequencies))] for i in xrange(5): line = "" for j in xrange(5): line += letters[bisect_left(cumulative_frequencies, random() * cumulative_frequencies[-1])] + " " print line
The idea is for each letter generated to use the roulette wheel algorithm to select it randomly with a probability proportional to the given frequencies.
source share