Skip to content

Instantly share code, notes, and snippets.

@hyotang666
Created March 13, 2016 23:56
Show Gist options
  • Save hyotang666/ffa6847da2b0e9a2b629 to your computer and use it in GitHub Desktop.
Save hyotang666/ffa6847da2b0e9a2b629 to your computer and use it in GitHub Desktop.
;;; $ cat /dev/urandom | tr -cd [:alnum:] | fold -w 15 | head -n 5
;;; See CLHS especially alpha-char-p digit-char-p upper-case-p lower-case-p graphic-char-p alphanumericp
;;; when you need get radix 16 strings, you can use (lambda(c)(digit-char-p c 16))
(loop :repeat 5 :do (write-line(random-string 15 #'alphanumericp)))
(defun random-string(length &optional (pred #'characterp))
(with-open-file(s "/dev/urandom" :element-type '(signed-byte 8))
(loop :with string = (make-string length)
:for index :upfrom 0 :below length
:do (setf(schar string index)(ensure s pred))
:finally (return string))))
(defun ensure (byte-input-stream pred)
(loop(let((c(code-char(abs(read-byte byte-input-stream)))))
(when(funcall pred c)
(return c)))))
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment