;;;
;;;
;;; zenirc-random-nick.el --- Choose random nicks for ZenIRC

;;; Copyright (C) 1994 Ben A. Mesander

;;; Author: Ben A. Mesander <ben@gnu.ai.mit.edu>
;;; Maintainer: ben@gnu.ai.mit.edu
;;; Keywords: extensions
;;; Created: Sun Aug 14 20:20:05 MDT 1994

;;; $Id: zenirc-random-nick.el,v 1.0 1994/08/15 04:23:27 friedman Exp $

;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2, or (at your option)
;;; any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with this program; if not, you can either send email to this
;;; program's maintainer or write to: The Free Software Foundation,
;;; Inc.; 675 Massachusetts Avenue; Cambridge, MA 02139, USA.

;;; Commentary:

;;; This is really annoying.

;;; Code:

(require 'zenirc)

(random t)

;; note- the rfc lies about valid characters in nicks.
;; it appears the allowed character set is:
;; [0-9][A-^][a-|] and - and _
;; 0-9 and - cannot start a nick

(defun zenirc-random-nick-char ()
  (let ((c (abs (random 69)))) ; mmm, 69
    (cond ((= 0 c) "_") 
	  ((< c 10) (char-to-string (+ c 47))) ; 0-9
	  ((< c 40) (char-to-string (+ c 55))) ; A-^
	  (t (char-to-string (+ c 57))))))     ; a-|

(defun zenirc-random-nick-string (numchars)
  (let ((i 1) (str (zenirc-random-nick-char)))
    (if (< numchars 0)
	""
      (while (and (< (string-to-char str) 58)  ; can't start with
		  (> (string-to-char str) 47)) ; [0-9]
	(setq str (zenirc-random-nick-char)))
      (while (< i numchars)
	(setq str (concat str (zenirc-random-nick-char)))
	(setq i (1+ i)))
      str)))

(defun zenirc-random-nick ()
  (setq zenirc-nick (zenirc-random-nick-string 9)))

(zenirc-add-hook 'zenirc-mode-hook 'zenirc-random-nick)

(provide 'zenirc-random-nick)

;;; End of zenirc-random-nick.el
