all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Brad Collins <brad@studiojungle.net>
Subject: Re: How to create random characters?
Date: Thu, 18 Dec 2003 16:22:03 +0700	[thread overview]
Message-ID: <wk65ge32h0.fsf@studiojungle.net> (raw)
In-Reply-To: <wkr7z7oh2f.fsf@studiojungle.net> (Brad Collins's message of "Sun, 14 Dec 2003 16:59:52 +0700")

Brad Collins <brad@studiojungle.net> 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

  parent reply	other threads:[~2003-12-18  9:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-14  9:59 How to create random characters? Brad Collins
2003-12-14 11:10 ` Eli Zaretskii
     [not found] ` <mailman.53.1071403922.868.help-gnu-emacs@gnu.org>
2003-12-15  8:07   ` Joakim Hove
2003-12-15  8:46     ` Eli Zaretskii
2003-12-18  9:22 ` Brad Collins [this message]
     [not found] ` <mailman.242.1071742690.868.help-gnu-emacs@gnu.org>
2003-12-18 10:32   ` Kai Grossjohann
2003-12-18 17:30     ` Brad Collins
     [not found]     ` <mailman.280.1071771962.868.help-gnu-emacs@gnu.org>
2003-12-18 18:30       ` Harald Maier
2003-12-18 18:31       ` Kai Grossjohann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=wk65ge32h0.fsf@studiojungle.net \
    --to=brad@studiojungle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.