help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: comic-book-insult


From: Adam Porter
Subject: Re: comic-book-insult
Date: Sun, 08 Sep 2019 17:29:57 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> (defun scramble-string (str)
>   "Randomize the characters of a string."
>   (interactive "sscramble me: ")
>   (let*((empty-str  "")
>         (chars      (delete empty-str (split-string str empty-str)))
>         (rand-chars (sort chars (lambda (_ __) (zerop (random 2)))))
>         (rand-str   (mapconcat 'identity rand-chars ""))
>         )
>     rand-str) )
>
> (defun comic-book-insult ()
>   (interactive)
>   (insert (concat (scramble-string "@#$%&") "!") ))
>
> ;; (comic-book-insult) ; %@&$#!
> ;; (comic-book-insult) ; $%#@&!

seq.el makes this even easier:

    (seq-sort (lambda (_ _)
                (zerop (random 2)))
              "01234")  ;;=> "01423"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]