From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Scott Newsgroups: gmane.emacs.help Subject: Incredible shrinking list.... Date: Fri, 17 Oct 2008 14:47:42 -0600 Message-ID: <20081017204742.GB1614@drmemory.local> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1224302214 12710 80.91.229.12 (18 Oct 2008 03:56:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 18 Oct 2008 03:56:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Oct 18 05:57:54 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Kr2ws-0002Yz-AH for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Oct 2008 05:57:54 +0200 Original-Received: from localhost ([127.0.0.1]:45068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kr2vn-0003ex-Fl for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Oct 2008 23:56:47 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KqwFD-0000cW-5k for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 16:48:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KqwFA-0000cH-0K for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 16:48:22 -0400 Original-Received: from [199.232.76.173] (port=44191 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KqwF9-0000cE-RE for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 16:48:19 -0400 Original-Received: from outbound.vnet-inc.com ([216.146.104.103]:3727) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KqwF9-000058-Cv for help-gnu-emacs@gnu.org; Fri, 17 Oct 2008 16:48:19 -0400 Original-Received: from drmemory.local (unknown [65.19.224.40]) by outbound.vnet-inc.com (Postfix) with SMTP id 15A3257AA for ; Fri, 17 Oct 2008 14:48:18 -0600 (MDT) Original-Received: (qmail 1679 invoked by uid 501); 17 Oct 2008 20:47:42 -0000 Content-Disposition: inline User-Agent: Mutt/1.5.16 (2007-06-09) X-detected-operating-system: by monty-python.gnu.org: FreeBSD 4.6-4.9 X-Mailman-Approved-At: Fri, 17 Oct 2008 23:52:52 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58896 Archived-At: Hi, I am very much a newbie, so forgive if this is a stupid question. I am trying to write a function which returns a randomized permutation of a certain number of items. Here is my stab at it, and the problem which baffles me: (defun pick-ten () "Pick a series of ten unique random numbers from 0-9. You should ensure that random is properly 'seeded', as eg: (random t) prior to using this function." (let ((all-ten '(0 1 2 3 4 5 6 7 8 9)) ;initial list (rnd-list '()) ;return value (nxt 0)) ;placeholder for current number (while all-ten ;step through the list (setq all-ten ;trim by (delq ;deleting selected number (setq nxt ;but remember number for later (car (nthcdr (mod (random)(length all-ten)) all-ten) ) ) all-ten)) (setq rnd-list (cons nxt rnd-list)) ;and put into the return value ) rnd-list ;now return it. )) ;; works fine on the first evaluation, ;; but the series somehow shrinks with subsequent calls! ;; what am I doing wrong???! ;; (pick-ten)(3 2 9 7 1 6 0 5 8 4) (pick-ten)(1 0 2 3) (pick-ten)(0 1) (pick-ten)(0) (version)"GNU Emacs 21.3.2 (i586-pc-linux-gnu, X toolkit) of 2004-07-02 on DrMemory" (time-to-upgradep (version))t I'm sure there is a far better way to write this, but I can't for the life of me figure out why my ham-handed attempt is acting so bizarrely, and would appreciate any help! thanks, Scott swanson