From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Jesper Harder Newsgroups: gmane.emacs.help Subject: Re: UUIDGEN in lisp Date: Sun, 15 Feb 2004 01:27:31 +0100 Organization: http://purl.org/harder/ Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1076805261 13456 80.91.224.253 (15 Feb 2004 00:34:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 15 Feb 2004 00:34:21 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 15 01:34:15 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AsAEh-0001r0-00 for ; Sun, 15 Feb 2004 01:34:15 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AsABW-000499-2g for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Feb 2004 19:30:58 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!not-for-mail Original-Newsgroups: gnu.emacs.help X-Face: ^RrvqCr7c,P$zTR:QED"@h9+BTm-"fjZJJ-3=OU7.)i/K]<.J88}s>'Z_$r; List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:16864 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:16864 Brad Collins writes: > But I really do need to use a proper UUID. > > I've been trying to see how it's been done by others but it's not > easy stuff. I still don't understand about high and low parts of a > time stamp and how to convert them.. Well, the time-based UUID is annoying to generate -- it requires system-wide storage of a seed. I don't see how you can guarantee that your generator will use the same storage as, say, the Perl generator and whatever else might generate UUIDs on ms-windows. This type of UUID also leaks your MAC address. Random-based UUIDs are much nicer. Below is an implementation. It uses /dev/urandom as a source of high quality random bits on GNU/Linux, but I don't know if the built-in `random' in Emacs used on other systems qualifies as a "cryptographic strength random number generator". (defun uuid () "Generate a version 4 UUID." (let ((bytes (uuid-random))) (setf (nth 7 bytes) (logior #B01000000 (logand #B01111111 (nth 7 bytes)))) (setf (nth 8 bytes) (logior #B01000000 (logand #B01001111 (nth 8 bytes)))) (apply 'format "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" bytes))) (defun uuid-random () "Return a list of 16 random bytes." (if (file-readable-p "/dev/urandom") (let (((coding-system-for-read 'binary))) (mapcar 'identity (substring (string-as-unibyte (shell-command-to-string "dd count=16 bs=1 < /dev/urandom")) 0 16))) (random t) (mapcar 'random (make-list 16 255))))