Guest User

Untitled

a guest
Jul 21st, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.72 KB | None | 0 0
  1. (defun generate-passphrase ()
  2.   "Generate a passphrase from the given text in buffer."
  3.   (interactive)
  4.   (let ((words-hash (make-hash-table :test 'equal :size 6000)))
  5.     (save-excursion
  6.       (goto-char (point-min))
  7.       (while (re-search-forward "\\w+" (point-max) t)
  8.         (let ((word (downcase (match-string 0))))
  9.           (if (= 0 (gethash word words-hash 0))
  10.               (puthash word 1 words-hash))
  11.           word)))
  12.     (let ((words '())
  13.           (phrase '()))
  14.       (maphash (lambda (x y) (push x words)) words-hash)
  15.       (dotimes (n 7 phrase)
  16.         (setq phrase (cons (nth (random (length words)) words)
  17.                            phrase)))
  18.       (message "%S %S words" phrase (length words)))))
Add Comment
Please, Sign In to add comment