Apr 27 2009
Snippet to generate a random word in python
Since I haven't posted here in a while, I figured I'd whip up this example real quick. It illustrates the usage of the random function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #!/usr/bin/python import random from time import time def generateWord(): char_array = 'abcdefghijklmnopqrstuvwxyz' random.seed(time()) word = '' for i in range(0, 8): # 8 letter word word += char_array[random.randint(0, 25)] return word if __name__ == '__main__': print generateWord() |