From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Brad Collins Newsgroups: gmane.emacs.help Subject: Re: How to create random characters? Date: Thu, 18 Dec 2003 16:22:03 +0700 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 1071739183 14124 80.91.224.253 (18 Dec 2003 09:19:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 18 Dec 2003 09:19:43 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 18 10:19:34 2003 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 1AWuJh-0000ky-00 for ; Thu, 18 Dec 2003 10:19:33 +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 1AWvEh-0007y9-6c for geh-help-gnu-emacs@m.gmane.org; Thu, 18 Dec 2003 05:18:27 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AWvEO-0007wl-Ik for help-gnu-emacs@gnu.org; Thu, 18 Dec 2003 05:18:08 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AWvDr-0007qK-21 for help-gnu-emacs@gnu.org; Thu, 18 Dec 2003 05:18:06 -0500 Original-Received: from [202.183.255.5] (helo=mailgw.cscoms.com) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AWvDp-0007q2-Uy for help-gnu-emacs@gnu.org; Thu, 18 Dec 2003 05:17:34 -0500 Original-Received: from cscoms.com (mail.cscoms.com. [202.183.255.23]) by mailgw.cscoms.com (8.12.8p2/8.12.3) with ESMTP id hBI9FkdB087647 for ; Thu, 18 Dec 2003 16:15:47 +0700 (ICT) Original-Received: from KAME.cscoms.com ([203.170.158.228]) by cscoms.com (8.12.8p2/8.12.3) with ESMTP id hBI9FgDh004025 for ; Thu, 18 Dec 2003 16:15:46 +0700 (GMT) Original-To: help-gnu-emacs In-Reply-To: (Brad Collins's message of "Sun, 14 Dec 2003 16:59:52 +0700") User-Agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (windows-nt) X-Virus-Scanned: by amavisd-milter (http://amavis.org/) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor 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:15403 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:15403 Brad Collins writes: > I'm hoping there is a simple function in elisp to do this.... > > I want to generate a random id which is in the format of XXX-0000 > where 'XXX' is made up of ascii characters a-z and 0000 is a random > number 0000-9999. > Thanks to all who helped! I did find if you use Emacs' "random" function, it will always use the same seed to generate random numbers. You can use (random t) to use a different seed, and get different random sequences every time, but my function uses this argument as a limit. So every time I would restart Emacs I'd get the same sequence of random IDs. So I switched to using the clisp function random* and it seems to work. Here is the function I finally came up with. There is probably a better way of doing this, and yes, tt's trivial, but seems to work and might be of use to someone. (defun insert-bxid () "Insert random Burr Exchange ID (BXID) at point. BXID's are based on the old telephone exchange numbers which are easy to remember and can be used mnemonically. For example: WAL5-9000 could be remembered as Walnut Five--Nine Thousand. To deal with potential conflicts between duplicate ID's, BXID's are mapped to both a namespace (xml style) which points to an Exchange Registry as well as a UUID which is universally unique." (interactive) (require 'cl) (insert (format "%c%c%c" (+ ?A (random* (- ?Z ?A))) (+ ?A (random* (- ?Z ?A))) (+ ?A (random* (- ?Z ?A)))) (format "%d" (random* 9)) "-" (format "%d%d%d%d" (random* 9 ) (random* 9 ) (random* 9 ) (random* 9)))) Thanks again! b/ -- Brad Collins Chenla Labs Bangkok, Thailand