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 21:47:44 +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 1076878982 2751 80.91.224.253 (15 Feb 2004 21:03:02 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 15 Feb 2004 21:03:02 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 15 22:02:56 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 1AsTPk-00078P-00 for ; Sun, 15 Feb 2004 22:02:56 +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 1AsTNy-0003Nb-Ls for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Feb 2004 16:01:06 -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:16879 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:16879 Brad Collins writes: > The major mode I'm working on will be GPL'd, is it okay to include > this code in the mode? Sure. > Interesting to see that if you call the script twice in less than a > second you get a duplicate id.... not sure why, but it means that > one should take care it in scripts.... Ah, yes. It happens because of the `(random t)' in `uuid-random'. It seeds the RNG, which is necessary because otherwise you'll always get the same sequence of random number. But Emacs uses the current time (plus pid) as the seed, so you'll get the same numbers if you call it with intervals shorter than the time resolution. So you should remove the (random t) from the function: (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))) (mapcar 'random (make-list 16 255)))) and just place it at the top-level (or in the function that starts your mode).