Skip to content

Instantly share code, notes, and snippets.

Created September 10, 2012 23:55
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Modern password generation with NLTK
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import random
>>> random.seed()
>>> import nltk
>>> from nltk.corpus import wordnet as wn
>>> nouns, verbs, adjectives, adverbs = [list(wn.all_synsets(pos=POS)) for POS in [wn.NOUN, wn.VERB, wn.ADJ, wn.ADV]]
>>> def gen_phrase(*pattern): return [random.choice(i) for i in pattern]
>>> def phrase_to_string(phrase): return ' '.join(s.lemmas[0].name for s in phrase)
>>> def gen_password(): return phrase_to_string(gen_phrase(adverbs, adjectives, adjectives, nouns))
>>> gen_password()
'decidedly Noachian autoplastic bag_lady'
>>> gen_password()
'ad_val faithful regimented accordance'
>>> gen_password()
'familiarly votive empty Gadiformes'
>>> gen_password()
'universally surmountable wiry field_mouse'
>>> gen_password()
'deadpan bilingual grandiose oxygen_deficit'
>>> gen_password()
'flip-flap heterozygous unenlightened solitaire'
>>> gen_password()
'only piquant apart Massawa'
>>> gen_password()
'continuously forty-two coarse-haired Israel'
>>> gen_password()
'actually trigger-happy tactful cobia'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment