This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/4] Disallow use of DES encryption functions in new programs.
On Tue, 22 May 2018, Rical Jasan wrote:
> > -@code{strfry} creates a pseudorandom anagram of a string, replacing the
> > -input with the anagram in place. For each position in the string,
> > -@code{strfry} swaps it with a position in the string selected at random
> > -(from a uniform distribution). The two positions may be the same.
> > +@code{strfry} performs an in-place shuffle on @var{string}. Each
> > +character is swapped to a position selected at random, within the
> > +portion of the string starting with the character's original position.
> > +(This is the Fisher-Yates algorithm for unbiased shuffling.)
>
> I like the "pseudorandom anagram" analogy, personally, as it's
> rearranging a string. What about combining the two? I'm not sure we
> even need to go into this much detail about how it happens, though I do
> think it's good to mention that it happens "in-place" (which both
> versions do). What about:
>
> @code{strfry} creates a pseudorandom anagram of @var{string}, replacing
> it in-place using the Fisher-Yates algorithm for unbiased shuffling.
Note that there's the pre-existing condition that, contrary to the
documentation, the distribution is not actually uniform (especially for
very long strings), because it uses a random nonnegative 32-bit integer
modulo the remaining length of the string (see bug 4403). (As a
pre-existing condition, this is not a problem with any variant of this
patch.)
--
Joseph S. Myers
joseph@codesourcery.com