Skip to content

Instantly share code, notes, and snippets.

@jweaver
Last active February 8, 2018 22:35
Show Gist options
  • Save jweaver/70f42c91b00f20b5b31bee2828ccef2c to your computer and use it in GitHub Desktop.
Save jweaver/70f42c91b00f20b5b31bee2828ccef2c to your computer and use it in GitHub Desktop.
Emacs function to insert a random UUID on-demand.From http://ergoemacs.org/emacs/elisp_generate_uuid.html
(random t)
(defun insert-random-uuid ()
"Insert a random UUID.
Example of a UUID: 1df63142-a513-c850-31a3-535fc3520c3d
WARNING: this is a simple implementation. The chance of generating the same UUID is much higher than a robust algorithm.."
(interactive)
(insert
(format "%04x%04x-%04x-%04x-%04x-%06x%06x"
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 4))
(random (expt 16 6))
(random (expt 16 6)) ) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment