unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Random number generation in LISP or using it
Date: Wed, 08 Jul 2009 14:57:50 +0200	[thread overview]
Message-ID: <7cr5wre3ht.fsf@pbourguignon.anevia.com> (raw)
In-Reply-To: 877hyjcrv0.fsf@x2.delysid.org

Mario Lang <mlang@delysid.org> writes:

> bolega <gnuist006@gmail.com> writes:
>
>> What is a fast(est) method to randomize lines based on the
>> capabilities of emacs ?
>
> C-x h C-u M-| sort -R

This is not what was asked. sort -R puts together equal lines.  AFAIK,
-R exists only in GNU sort, so it hasn't even the excuse of being
available everywhere emacs is available (see:
http://www.informatimago.com/linux/emacs-on-user-mode-linux.html
;-) )


(require 'cl) ; for coerce
(require 'cookie1) ; for shuffle-vector

(defun randomize-lines-of-region (start end)
  (interactive "r")
  (let* ((start (progn (goto-char start) (beginning-of-line) (point)))
         (end   (progn (goto-char end)   (end-of-line)       (point)))
         (lines (shuffle-vector (coerce (split-string (buffer-substring start end) "\n") 'vector))))
    (delete-region start end)
    (insert (aref lines 0))
    (dotimes (i (1- (length lines)))
       (insert "\n" (aref lines (1+ i))))))

    
-- 
__Pascal Bourguignon__


      reply	other threads:[~2009-07-08 12:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-10 15:21 Random number generation in LISP or using it bolega
2009-06-10 15:26 ` bolega
2009-06-10 18:04 ` Colin S. Miller
2009-06-10 18:56   ` Lennart Borgman
2009-06-10 18:21 ` Thomas A. Russ
2009-06-10 18:21 ` Thomas A. Russ
2009-06-10 21:57 ` Xah Lee
2009-06-11  7:34 ` TomSW
2009-07-08 11:54 ` Mario Lang
2009-07-08 12:57   ` Pascal J. Bourguignon [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=7cr5wre3ht.fsf@pbourguignon.anevia.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).