help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random number generation in LISP or using it


From: Pascal J. Bourguignon
Subject: Re: Random number generation in LISP or using it
Date: Wed, 08 Jul 2009 14:57:50 +0200
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux)

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 via email to

[Prev in Thread] Current Thread [Next in Thread]