From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.help Subject: Re: random predicate function Date: Mon, 13 Dec 2010 11:16:21 -0600 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <87r5dlmw4a.fsf@lifelogs.com> References: <87mxo9r8xg.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1292281069 6735 80.91.229.12 (13 Dec 2010 22:57:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 13 Dec 2010 22:57:49 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Dec 13 23:57:42 2010 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.69) (envelope-from ) id 1PSHKu-0007OX-Lw for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Dec 2010 23:57:40 +0100 Original-Received: from localhost ([127.0.0.1]:57130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PSHKu-0001SL-AZ for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Dec 2010 17:57:40 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!news.wiretrip.org!news2.arglkargh.de!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 37 Original-X-Trace: news.albasani.net 3dMiiAEqlmr8xOwDgFfeQsk792t/jY2i8fphU4DMgGKzHtnmC4ZAGdwHkEgKGv2JJnITjq5vJophXQwh3PgAlJGNU2MlJOSZpzyLLq1Y9EOA8/2MtcRHY2tPMS3a6sB7 Original-NNTP-Posting-Date: Mon, 13 Dec 2010 17:16:21 +0000 (UTC) X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Cancel-Lock: sha1:XBGUl8V4DJIAwnVOCcT7AVOh/kY= sha1:HK7aqK3wn3U9X9RLgEOh1oKduKY= User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) Injection-Info: news.albasani.net; logging-data="cGatDq8krUWkwo/sPaFOEzcMFY9ofzTARU2f0+Bqo68zcNDszbWkUeJXwKyqv34dnm/iXXSDlp+nNPlNp6kP22wHVnnWW45DAP/6LtR9vxErJLbXtzw3nljw+xx6ym35"; mail-complaints-to="abuse@albasani.net" Original-Xref: usenet.stanford.edu gnu.emacs.help:183214 X-Mailman-Approved-At: Mon, 13 Dec 2010 17:55:22 -0500 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:77474 Archived-At: On Mon, 13 Dec 2010 16:26:03 +0100 "Pascal J. Bourguignon" wrote: PJB> You could instead put your paragraphs in a vector and use: PJB> (defun shuffle (vector) PJB> "Re-orders randomly the vector." PJB> (loop PJB> for i from (1- (length vector)) downto 1 PJB> do (rotatef (aref vector i) (aref vector (random i))))) PJB> to shuffle them and then re-insert them. I noticed this function in lisp/play/cookie1.el which doesn't require CL: ; Thanks to Ian G Batten ; [of the University of Birmingham Computer Science Department] ; for the iterative version of this shuffle. ; ;;;###autoload (defun shuffle-vector (vector) "Randomly permute the elements of VECTOR (all permutations equally likely)." (let ((i 0) j temp (len (length vector))) (while (< i len) (setq j (+ i (random (- len i)))) (setq temp (aref vector i)) (aset vector i (aref vector j)) (aset vector j temp) (setq i (1+ i)))) vector) I wonder if it should be moved out of cookie1.el. Ted