gen.py revision 926c960e
149cab51aSShuo Chen#!/usr/bin/python 249cab51aSShuo Chen 3926c960eSShuo Chenimport numpy 449cab51aSShuo Chen 5926c960eSShuo Chenwords = 1000*1000 6926c960eSShuo ChenS = 1.05 7926c960eSShuo ChenALPHABET = '_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' 849cab51aSShuo Chen 9926c960eSShuo Chendef number2word(x): 10926c960eSShuo Chen assert x > 0 11926c960eSShuo Chen arr = [] 12926c960eSShuo Chen base = len(ALPHABET) 13926c960eSShuo Chen div = x 14926c960eSShuo Chen while div > 0: 15926c960eSShuo Chen div, mod = divmod(div, base) 16926c960eSShuo Chen arr.append(ALPHABET[mod]) 17926c960eSShuo Chen return ''.join(arr) 1849cab51aSShuo Chen 19926c960eSShuo Chenoutput = open('random_words', 'w') 20926c960eSShuo Chen 21926c960eSShuo Chenfor x in xrange(words): 22926c960eSShuo Chen word = number2word(numpy.random.zipf(S)) 2349cab51aSShuo Chen output.write(word) 2449cab51aSShuo Chen output.write('\n') 2549cab51aSShuo Chen 26