From 23203bf9cac8bc28f21ff6e1260463535d0b7672 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 11 Nov 2021 10:03:20 -0700 Subject: add RANDOM-ALPHANUMERIC Signed-off-by: Sean Whitton --- src/util.lisp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/util.lisp') diff --git a/src/util.lisp b/src/util.lisp index cee463f..0bbf585 100644 --- a/src/util.lisp +++ b/src/util.lisp @@ -373,6 +373,14 @@ expansion as a starting point for your own DEFPACKAGE form for your consfig." "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" :test #'string=) +(defun random-alphanumeric (length) + "Return a random alphanumeric string of length LENGTH." + (aprog1 (make-string length) + (loop with *random-state* = (make-random-state t) + for i below length + do (setf (char it i) + (char +alphanum+ (random #.(length +alphanum+))))))) + (defun mkfifo () "Use mkfifo(3) to create a named pipe with a mkstemp(3)-like name." (let* ((dir (drop-trailing-slash (or (getenv "TMPDIR") "/tmp"))) -- cgit v1.2.3