From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: comic-book-insult Date: Mon, 9 Sep 2019 12:09:08 +0700 Message-ID: References: <86k1aiip6o.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="165358"; mail-complaints-to="usenet@blaine.gmane.org" To: Emanuel Berg , help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 09 07:09:36 2019 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1i7Bvj-000gtb-Ku for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Sep 2019 07:09:35 +0200 Original-Received: from localhost ([::1]:52214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7Bvh-0000FC-Sp for geh-help-gnu-emacs@m.gmane.org; Mon, 09 Sep 2019 01:09:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44499) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7BvX-0000F1-24 for help-gnu-emacs@gnu.org; Mon, 09 Sep 2019 01:09:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7BvV-0003Hd-Ud for help-gnu-emacs@gnu.org; Mon, 09 Sep 2019 01:09:22 -0400 Original-Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]:37658) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7BvV-0003Fq-Ns for help-gnu-emacs@gnu.org; Mon, 09 Sep 2019 01:09:21 -0400 Original-Received: by mail-ed1-x52f.google.com with SMTP id i1so11754495edv.4 for ; Sun, 08 Sep 2019 22:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-transfer-encoding; bh=8ERoayWoJYPlhIAgZNgNpTM1r8w1/7sfMw+FJ0PFm+M=; b=lLGNa4btKVDDgy8osFmsSASi2ypA5b5969iCmJQ6GzAqCAMXOwvy6tiN4WG/m7F+p3 ZIz5n7QQYOQCmKjyfn2QdIFBKHtukctP9FkWZlF7R6cfj9+lQ96Ev3o7jsydiZqF0/LH qkQOBQX3Ju1WTigkO3jtKToS9krzwuNH2sbHEJ6TaSt8pi8o/Y+ME3PY7jF9uey9E383 6V53frL1n2eU6Vjz9TGjN4dRmkeqUe/Ok86CWfptKhEwkAP2eQxS2IzC7aRKqPLhO3oY Bjp93yE+/AWDU6NuUw9ofaJ7WgNKcxRUMKVAl/QkvJZ2moiKheEq8hBsqI2cbQ0JdgU6 EJlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-transfer-encoding; bh=8ERoayWoJYPlhIAgZNgNpTM1r8w1/7sfMw+FJ0PFm+M=; b=UQOcwQG7t+i8DzgAyTmI+XazdE5DzjTKuX/JCqGl0kkeLTSARHWKwA8l7oIiG3jNV6 AhVHCYua5P8x4KluvLQDuEc5F4S4IKvrn7aeBT/0WogHJUym/fOeeusvGAl35oNf/tye HP7TgS+LAQz7G+WSynlxg1Wpq1uqy+oyL1WT16MsQqON1q1PMzF8HnPREKFYq7Jc5PXw qdMeoQbxUSUYJHq2TXMxBgljVTt3VhddjuzQJ2ZH7xGTIGbcvylmTI9GPe0iH9GGdiHx P0LlEcWFIZthrhjn6+6GqXj6cUA62xWtqNxrrRtXLilAMV2ZVYtHtpDYwwpCKEw/stRh Cvpg== X-Gm-Message-State: APjAAAWJCVkY3tyqO8dUHDgwo1wortiOUxtJyUGYqCJ2xFdIokDLQq2D Q+0jsO32YpLccu33gp8DR1NznlSgRoLlKRZ5Swo= X-Google-Smtp-Source: APXvYqxsSXo8APVOlu6/dxbwDOeo0+DwbaNweVxud0cSCO2HUhAKuvhLyI02Kt1Zhg266C+NgYzX2kfBX9dpyey8fPg= X-Received: by 2002:a05:6402:8ce:: with SMTP id d14mr22525490edz.244.1568005759924; Sun, 08 Sep 2019 22:09:19 -0700 (PDT) In-Reply-To: <86k1aiip6o.fsf@zoho.eu> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::52f X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:121487 Archived-At: On Mon, 9 Sep 2019 at 02:05, Emanuel Berg via Users list for the GNU Emacs text editor wrote: > (rand-chars (sort chars (lambda (_ __) (zerop (random 2))))) If you were to pull off this kind of thing in C or C++, that would be classified as undefined behavior and possibly cause demons to fly out your nose. The comparison predicate used in sorting algorithms must be a strict weak ordering, i.e.: * irreflexive =E2=80=94 (not (p x x)) for each x; * antisymmetric =E2=80=94 if (p x y), then (not (p y x)); * transitive =E2=80=94 if (p x y) and (p y z), then (p x z); * the equivalence induced by it must also be transitive =E2=80=94 if (not (= or (p x y) (p y x))) and (not (or (p y z) (p z y))), then (not (or (p x z) (p z x))). A predicate that returns a random boolean on each invocation will easily violate any or all of the above. The canonical lazy coder way to random-shuffle a collection is to first associate a random value with each element, then sort by that: (concat (seq-map #'car (seq-sort-by #'cdr #'< (seq-map (lambda (x) (cons x (random))) (string-to-vector "@#$%&"))))) (This whole sorting approach is criticized because it is O(n log n) in the number of elements while there exist random shuffle algorithms that are linear, i.e. O(n). See [1].) [1]: https://stackoverflow.com/a/1287572/1326190