# L-37 MCS 275 Wed 14 Apr 2010 : randomwords.py # Auxiliary module for "conversation.py" import random def RandomWord(n): """ Returns a random word of n lower case letters. """ s = '' for i in range(0,n): r = random.randint(ord('a'),ord('z')) s = s + chr(r) return s def RandomSentence(n,m): """ Returns a random sentence of n random words, separated by spaces. Every word is between 1 and m characters long. """ s = '' for i in range(0,n): L = random.randint(1,m) w = RandomWord(L) if s == '': s = w else: s = s + ' ' + w return s def main(): """ Test on random words. """ n = input('give n : ') m = input('give m : ') w = RandomSentence(n,m) print 'random words :', w if __name__=="__main__": main()