2

Suppose I has text:

test hello

The cursor is after word test. I need to insert random number? Also I need to set range of random (e.g. from 0 to 1000)

The result maybe like this:

test100 hello
Drew
  • 75,699
  • 9
  • 109
  • 225
a_subscriber
  • 3,854
  • 1
  • 17
  • 47
  • 2
    What is your question? Maybe, the following page answers it: http://www.wilkesley.org/~ian/xah/emacs/elisp_insert_random_number_string.html. An on-the-fly solution would be: `M-: (insert (format "%d" (random 1000)))`. – Tobias Aug 26 '19 at 13:42
  • 1
    @tobias just curious, why link to that mirror instead of Xah's site? http://ergoemacs.org/emacs/elisp_insert_random_number_string.html – Tyler Aug 26 '19 at 18:52

1 Answers1

3
(defun my-random-number-insert-at-point ()
  "Insert a random number between 0 and 1000."
  (interactive)
  (insert (number-to-string (random 1000))))
jagrg
  • 3,824
  • 4
  • 19
  • 2
    Don't call `(random t)` since it should be unnecessary. Also, please indent your code properly so it's more readable. Also, you may like to check the consistency between your docstring and your code ;-) – Stefan Aug 26 '19 at 15:59