Add gint to apply a function with a probability

This commit is contained in:
Bram Schoenmakers 2023-04-14 18:55:53 +02:00
parent ea141d8fe4
commit 1f0b56cc5a
2 changed files with 15 additions and 0 deletions

View File

@ -527,6 +527,16 @@ It turns out it didn't work as well as I hoped, paredit steals the RET binding s
:post-process-template #'my/dwim-shell-command/convert-path-cygwin))
#+end_src
* Apply maybe
#+begin_src elisp :tangle gists/apply-maybe.el
(defun my/apply-maybe (f probability &rest args)
"Apply function F with a certain PROBABILITY [0-1)."
(if (< (random 100) (* probability 100))
(apply f args)
'my/not-applied))
#+end_src
* Meta
** License

5
gists/apply-maybe.el Normal file
View File

@ -0,0 +1,5 @@
(defun my/apply-maybe (f probability &rest args)
"Apply function F with a certain PROBABILITY [0-1)."
(if (< (random 100) (* probability 100))
(apply f args)
'my/not-applied))