Created
March 13, 2016 23:56
-
-
Save hyotang666/ffa6847da2b0e9a2b629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; $ 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