2011-02-26

emacs lisp: generate a ID

I want a command to insert random strings, as a ID. So i wrote one:

(defun insert-random-string ()
  "Insert a random alphanumerics string of length 6."
  (interactive)
  (let (mycharset (ii 0) )
    (setq mycharset ["1" "2" "3" "4" "5" "6" "7" "8" "9" "0" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" ] )

    (while (< ii 6)
      (insert (elt mycharset (random (length mycharset))))
      (setq ii (1+ ii) ) ) ) )

O emacs! ♥

See also: Emacs Lisp Examples (Page 1)