Files
.emacs.d/modules/misc/siren-rand.el
Jim Myhrberg fe6a4e7ce5 fix(elisp): add lexical-binding comment to all files to suppress new Emacs 31 warnings
I've set `lexical-binding` to `nil` in all Emacs Lisp files to suppress
the warnings introduced in Emacs 31 requiring all elisp files to have a
`lexical-binding` comment.

This retains the default behavior of dynamic binding when no
`lexical-binding` comment is present. With it set to `t` across the
board, various things break, and fixing those is a task for another day.
2025-06-29 12:23:03 +01:00

51 lines
1.4 KiB
EmacsLisp

;;; siren-rand.el --- jimeh's Emacs Siren: rand configuration. -*- lexical-binding: nil; -*-
;;; Commentary:
;; Basic configuration for rand.
;;; Code:
;; Borrowed from:
;; http://ergoemacs.org/emacs/elisp_insert_random_number_string.html
;; seed random number
(random t)
(defun rand-alphanumeric (NUM)
"Insert a random alphanumerics string of length NUM."
(interactive "P")
(let* ((charset (concat "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"))
(baseCount (length charset)))
(dotimes (_ (if (numberp NUM) (abs NUM) 16))
(insert (elt charset (random baseCount))))))
(defun rand-hex (NUM)
"Insert NUM random hexadecimal digits."
(interactive "P")
(let ((n (if (numberp NUM) (abs NUM) 6 )))
(insert (format
(concat "%0" (number-to-string n) "x" )
(random (1- (expt 16 n)))))))
(defun rand-num (NUM)
"Insert NUM random digits."
(interactive "P")
(let ((charset "1234567890")
(baseCount 10))
(dotimes (_ (if (numberp NUM) (abs NUM) 16 ))
(insert (elt charset (random baseCount))))))
(defun rand-ip ()
"Insert a random IPv4 address."
(interactive)
(insert (concat (int-to-string (random 255))
"." (int-to-string (random 255))
"." (int-to-string (random 255))
"." (int-to-string (random 255)))))
(provide 'siren-rand)
;;; siren-rand.el ends here