[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
same sound random sort everywhere (was: Re: avoid narrow-to-region (was:
From: |
Emanuel Berg |
Subject: |
same sound random sort everywhere (was: Re: avoid narrow-to-region (was: Re: replace-regexp)) |
Date: |
Fri, 21 May 2021 19:35:55 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
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
;;; https://dataswamp.org/~incal/emacs-init/random-generic.el
(require 'cl-lib)
;; add more datatypes here... (for each type, one disassembler,
;; one call to nshuff, and one assembler is needed)
(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")
;; ... all use the same random-sort algorithm
(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) ...
--
underground experts united
https://dataswamp.org/~incal
- 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 <=
- Re: same sound random sort everywhere (was: Re: avoid narrow-to-region (was: Re: replace-regexp)), Jean Louis, 2021/05/21
- 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