[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: same sound random sort everywhere (was: Re: avoid narrow-to-region (
From: |
Jean Louis |
Subject: |
Re: same sound random sort everywhere (was: Re: avoid narrow-to-region (was: Re: replace-regexp)) |
Date: |
Fri, 21 May 2021 23:12:18 +0300 |
User-agent: |
Mutt/2.0.6 (2021-03-06) |
* Emanuel Berg via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> [2021-05-21 20:37]:
> Here we see it implemented for strings. If the nshuff
> algorithm is sound data type should - you guessed it - not
> influence anything in either way to make it more or less
> sound. See comments.
>
> ;;; -*- lexical-binding: t -*-
> ;;;
> ;;; this file:
> ;;; http://user.it.uu.se/~embe8573/emacs-init/random-generic.el
Not Found
The requested URL /~embe8573/emacs-init/random-generic.el was not found on this
server.
> ;;; https://dataswamp.org/~incal/emacs-init/random-generic.el
Found
> (require 'cl-lib)
For 1 single loop you download 26 kilobytes... ☻
> ;; add more datatypes here... (for each type, one disassembler,
> ;; one call to nshuff, and one assembler is needed)
That above I can understand somehow, but not this below, do you wish
to expand it?
(defun string-random (s)
(let*((str-lst (string-to-list s))
(lst (nshuff str-lst))
(str-shuff (mapconcat (lambda (c) (char-to-string c)) lst "")) )
str-shuff) )
;; (string-random "Elisp is my favorite E") ⇒ " ismitrEyaE lf oivpe s"
(defun nshuff (sq)
(cl-loop for i from (length sq) downto 2
do (cl-rotatef
(elt sq (cl-random i))
(elt sq (1- i)) ))
sq)
;; (nshuff '(a b c)) ; (b c a) (a b c) (b c a) ...
Great, now you can make Black Jack win/loose simulator.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
- Re: avoid narrow-to-region (was: Re: replace-regexp), (continued)
- Re: avoid narrow-to-region (was: Re: replace-regexp), Yuri Khan, 2021/05/09
- Re: avoid narrow-to-region (was: Re: replace-regexp), Emanuel Berg, 2021/05/09
- Re: avoid narrow-to-region (was: Re: replace-regexp), Yuri Khan, 2021/05/09
- Re: avoid narrow-to-region (was: Re: replace-regexp), Emanuel Berg, 2021/05/09
- Re: avoid narrow-to-region (was: Re: replace-regexp), Emanuel Berg, 2021/05/09
- Re: avoid narrow-to-region (was: Re: replace-regexp), Emanuel Berg, 2021/05/09
- Re: avoid narrow-to-region (was: Re: replace-regexp), Emanuel Berg, 2021/05/09
- same sound random sort everywhere (was: Re: avoid narrow-to-region (was: Re: replace-regexp)), Emanuel Berg, 2021/05/21
- Re: same sound random sort everywhere (was: Re: avoid narrow-to-region (was: Re: replace-regexp)),
Jean Louis <=
- Re: same sound random sort everywhere (was: Re: avoid narrow-to-region (was: Re: replace-regexp)), Emanuel Berg, 2021/05/21
Re: replace-regexp, Jean Louis, 2021/05/07