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

[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: Emanuel Berg
Subject: Re: same sound random sort everywhere (was: Re: avoid narrow-to-region (was: Re: replace-regexp))
Date: Fri, 21 May 2021 22:47:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis wrote:

>> 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

?

> For 1 single loop you download 26 kilobytes... ☻

???

I use cl-loop 26 times and FYI not just loops are in it...

>> ;; 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?

Use the source James :)

> (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.

check out upcoming virtual-vegas.el release

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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