[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: avoid narrow-to-region (was: Re: replace-regexp)
From: |
Yuri Khan |
Subject: |
Re: avoid narrow-to-region (was: Re: replace-regexp) |
Date: |
Sun, 9 May 2021 13:34:04 +0700 |
On Sun, 9 May 2021 at 13:10, Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> > * Consistency: If (f a b) returns t once, it must return
> > t when called again with the same arguments. [...]
>
> But here, we want to randomize _every time_.
Every time you do a random shuffle, but not within a single shuffle.
A theoretically sound (but still unnecessarily slow) sorting-based
shuffle would first assign a random weight to each line, and then sort
by that weight.
But contrast with this:
* Count the lines to be shuffled. Call it N.
* Generate a random number K_1 from 1 to N. Swap line 1 with line K_1.
* Generate a random number K_2 from 2 to N. Swap line 2 with line K_2.
…
* Generate a random number K_{N-1} from N-1 to N. Swap line N-1 with
line K_{N-1}.
Almost easy enough to put in Elisp, and guarantees uniform
distribution (as long as individual random indexes are uniformly
distributed).
- Re: replace-regexp, (continued)
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Stefan Monnier, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/08
- Re: replace-regexp, Emanuel Berg, 2021/05/09
- avoid narrow-to-region (was: Re: replace-regexp), Emanuel Berg, 2021/05/08
- 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 <=
- Re: avoid narrow-to-region (was: Re: replace-regexp), Emanuel Berg, 2021/05/09
- Re: avoid narrow-to-region (was: Re: replace-regexp), Jean Louis, 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), 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