kkk-random.el 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. ;;; kkk-random.el --- Function randomize things -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2023 Vinicius Teshima <vini.tes@pm.me>
  3. ;; Author: Vinicius Teshima <vini.tes@pm.me>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; Random Things
  16. ;;; Code:
  17. (defun kkk-list-get-random (list)
  18. "Get a random item from LIST."
  19. (elt list (random (length list))))
  20. (defun kkk-random-char ()
  21. "Return a random char."
  22. (char-to-string (+ 33 (random 94))))
  23. (defun kkk-random-string (length)
  24. "Create a random string with LENGTH chars."
  25. (let ((x ""))
  26. (dolist (_ (make-list length 0))
  27. (setq x (concat x (kkk-random-char)))
  28. )
  29. x
  30. )
  31. )
  32. (defun kkk-random-date (year)
  33. "Return a random date string on iso format (YYYY-MM-DD) using YEAR as year."
  34. (when (stringp year)
  35. (concat year "-" (int-to-string (+ (cl-random 12) 1))
  36. "-" (int-to-string (+ (cl-random 30) 1)))
  37. )
  38. )
  39. (provide 'kkk-random)
  40. ;;; kkk-random.el ends here