From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: 26.1; (random) never returns negative Resent-From: Francis Wright Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 01 Sep 2018 17:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Reply-To: f.j.wright@live.co.uk Received: via spool by submit@debbugs.gnu.org id=B.15358224542073 (code B ref -1); Sat, 01 Sep 2018 17:21:01 +0000 Received: (at submit) by debbugs.gnu.org; 1 Sep 2018 17:20:54 +0000 Received: from localhost ([127.0.0.1]:42076 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fw9Zu-0000XM-33 for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48463) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fw9Zt-0000X8-86 for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fw9Zi-0000vj-DK for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:45 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:45762) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fw9Zi-0000vT-3i for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fw9Ze-0001EW-L2 for bug-gnu-emacs@gnu.org; Sat, 01 Sep 2018 13:20:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fw9XB-0007i5-EX for bug-gnu-emacs@gnu.org; Sat, 01 Sep 2018 13:18:08 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:40209) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fw9XB-0007gg-7L for bug-gnu-emacs@gnu.org; Sat, 01 Sep 2018 13:18:05 -0400 Received: by mail-wr1-x42f.google.com with SMTP id n2-v6so13940832wrw.7 for ; Sat, 01 Sep 2018 10:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:reply-to:date:message-id:mime-version :content-transfer-encoding; bh=FsyHN41X96cC5fbiGYElqlMCmgnAQrpErD6+opD2St0=; b=tZJ/yMRyHQ3vobEELRCpds03mO4rDFVSDJpJ+zzzttYNxd65+kUqkaaVinYoUUmKNQ NK2+NX1/SI6+L9Pn+Od44aJlNvBw8LzY2b3+DYAw3Gh0RnqWSGkVUhqfABodtcXs3oek XPfvm7N8OOKXRGlrLNccNO+x00PUWBuRt8FYzW/UXUjrOFCyTqA2/5NWPHkjVHXcUBGr Q9OZD0vqAgmbOkynF1Zn9H7gCHdifBsLi++fd0yUrIwZUfgGGzCgKtjWgkoPtdbnpf8O svfdDWvHfVhp6374cy/huocNEjfdP1+IoQnc7UnQXQ6Br/B3UCR9yy+nMJjzilemjGd1 8iEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:reply-to:date:message-id :mime-version:content-transfer-encoding; bh=FsyHN41X96cC5fbiGYElqlMCmgnAQrpErD6+opD2St0=; b=Z8Vz2fZcFgrg1eAoXv8Ij3BZhOTR1v3WDk0u74lWZLDMPHRHDkOncDUCVqFRF+W+Do IsMxWWNU7XkbzHmU7AsCb6floLqOJy/1NOS4pB23l2ULn28AOANoN6Lh19u2EWOkpnOE 72UrjU8zbUtStqR5tyuljnnlk2xMglq2tktuyRJHJyuKsNi40QZZnxojBlRDyvuLajn+ x7dmNLqyd4AZU0GRa4h4vO30zgHZXexRWhYBpdd6eeO3cLpg6cbFLJfC8v7ZVrANqUaD DbCTdR8MrlByOZ057Axjr2WsaZPGk7d+4Vpx5w9+55uWJBVvh4luBw53udFo5PFDchsx 6Nzg== X-Gm-Message-State: APzg51CMMU22C9/Y5fjaD1I8tHN456DWIge7ZQHwEC7fvfzDkTtnJIow RnLuGvKWS9ZTqlq2LgtVp7XRBVqe X-Google-Smtp-Source: ANB0VdZrffPm2KmlnC3947QdAFyqhY6mM35Kbb8bmPpAFe+f/4zlUz9pRR+2HcxPVTmmx87xt+OE9g== X-Received: by 2002:adf:d84a:: with SMTP id k10-v6mr13276579wrl.26.1535822283371; Sat, 01 Sep 2018 10:18:03 -0700 (PDT) Received: from Monolith (host-92-19-191-141.as13285.net. [92.19.191.141]) by smtp.gmail.com with ESMTPSA id 75-v6sm15810157wml.21.2018.09.01.10.18.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Sep 2018 10:18:02 -0700 (PDT) From: Francis Wright Date: Sat, 01 Sep 2018 18:18:01 +0100 Message-ID: <855zzpf86u.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) According to my reading of both the documentation for the function random and its description in the manual, if it is called with no argument then "the value might be any integer representable in Lisp, i.e., an integer between =A1=AEmost-negative-fixnum=A1=AF and =A1=AEmost-positive-fixnum=A1=AF". Therefore, it should return a negative = integer half the time, but I have never yet seen it return a negative value. So either the documentation or the implementation is wrong. For what it's worth, I would prefer the documented behaviour over the current actual behaviour. In GNU Emacs 26.1 (build 1, x86_64-w64-mingw32) of 2018-05-30 built on CIRROCUMULUS Repository revision: 07f8f9bc5a51f5aa94eb099f3e15fbe0c20ea1ea Windowing system distributor 'Microsoft Corp.', version 10.0.17134 Recent messages: Canceling debug-on-entry for all functions You can run the command =A1=AEcancel-debug-on-entry=A1=AF with M-x ca-d-e R= ET Canceling debug-on-entry for all functions 1515484088033472457 / 2067076301065092720 t [2 times] Mark set [2 times] Saving file c:/Users/fjw/REDUCE@SourceForge/emacs/REDUCE/Big Integer Suppor= t/eslbigint.el... Wrote c:/Users/fjw/REDUCE@SourceForge/emacs/REDUCE/Big Integer Support/eslb= igint.el Type "q" in help window to restore its previous buffer. mwheel-scroll: End of buffer [6 times] mwheel-scroll: Beginning of buffer [9 times] Configured using: 'configure --without-dbus --host=3Dx86_64-w64-mingw32 --without-compress-install 'CFLAGS=3D-O2 -static -g3'' Configured features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS LCMS2 Important settings: value of $LANG: ENG locale-coding-system: cp1252 Major mode: Info Minor modes in effect: diff-auto-refine-mode: t shell-dirtrack-mode: t show-paren-mode: t delete-selection-mode: t electric-pair-mode: t tooltip-mode: t global-eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t buffer-read-only: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny rfc822 mml mml-sec epa derived epg gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils info eieio-opt speedbar sb-image ezimage dframe find-func help-fns radix-tree cl-extra thingatpt misearch multi-isearch edebug reposition time-stamp help-mode cl-print debug vc-git diff-mode easy-mmode vc-dispatcher vc-svn dired dired-loaddefs flyspell ispell imenu tramp tramp-compat tramp-loaddefs trampver ucs-normalize shell pcomplete comint ansi-color ring parse-time format-spec advice paren delsel cus-start cus-load finder-inf package easymenu epg-config url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs password-cache url-vars seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib elec-pair server time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite charscript charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote w32notify w32 lcms2 multi-tty make-network-process emacs) Memory information: ((conses 16 277958 12135) (symbols 56 26263 1) (miscs 48 215 603) (strings 32 53052 3399) (string-bytes 1 1403187) (vectors 16 43081) (vector-slots 8 801770 16514) (floats 8 79 425) (intervals 56 1601 17) (buffers 992 18)) From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: 26.1; (random) never returns negative Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 01 Sep 2018 17:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Francis Wright Cc: f.j.wright@live.co.uk, 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.15358232863458 (code B ref 32605); Sat, 01 Sep 2018 17:35:01 +0000 Received: (at 32605) by debbugs.gnu.org; 1 Sep 2018 17:34:46 +0000 Received: from localhost ([127.0.0.1]:42082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fw9nK-0000ti-Dl for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:34:46 -0400 Received: from mout.gmx.net ([212.227.15.19]:60417) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fw9nI-0000tS-IS for 32605@debbugs.gnu.org; Sat, 01 Sep 2018 13:34:45 -0400 Received: from rosalinde ([188.109.174.150]) by mail.gmx.com (mrgmx001 [212.227.17.190]) with ESMTPSA (Nemesis) id 0LvlTo-1fqUOu2J7E-017SQ8; Sat, 01 Sep 2018 19:34:36 +0200 From: Stephen Berman References: <855zzpf86u.fsf@gmail.com> Date: Sat, 01 Sep 2018 19:34:35 +0200 In-Reply-To: <855zzpf86u.fsf@gmail.com> (Francis Wright's message of "Sat, 01 Sep 2018 18:18:01 +0100") Message-ID: <87zhx1ktp0.fsf@gmx.net> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:MFBPEarz1yNUvgtEQ0b5i7TBa90PVkBCFiasdxhdQA1ehTukdAh UOQRg1JvBmLfBazWUHpEvfzThvhMElu6ICxrXI6WZA5UuWbORN8EK/dDUMcz0Fo99m1jXS/ uuTN/i0cZApfjnPDvaUJNWgoymHN37lYOfRKJzuteB/4VxOG01xkt/WwR5dpKAvqw0iLOl1 kOvx+TQhefaiosm0Y+Jxw== X-UI-Out-Filterresults: notjunk:1;V01:K0:HEauNe6kW3M=:nlStselhUoM9lofwZfPgZA JYHLdGeGA4decHpo5XqZFgKMC3dCDnCt45J4/1bD8NBhd2m+VXJIQ5waWQrate8eREd8OpjQC GEpTb//SMm8xFlNAMlF4zRieAk9bBsa61A9uec8R5YCSF+b81hgVtdbY5Jn75URlNTmgWVvru vYQ5WVwunbk80GrME+bWnspoRu3xFhmytfWjbB42TnyzqdSmRe3ADAi4ezdyxRBoaGb6g6cIi RT9p8hr6ZQpWbSkXhYm9ePuhFMPL1iC11RALn3d8npo/4/uLFkKb/vhHAqoeuGEedVED/uYr4 ckp8I1l2sXBJTzHLpRleG8yq0yfQIQzAck0FbyN/bsRwZToc2ZS91Qvj9Y/fRhMG4wMugYESk 6/dcVsR9WuFdZD5VajBS4mwCWGMNf86yl7gpaUofBhRSyuXMilY3kv9oUdjr60FZKhBGeZExW Pa7G48gKZ2ZrGGfh9BZskt7COiybNkZyF8YzyV+LQsd+DkZibeg+modr/uflqp83r4gPg7G9U ki8aYsFE7afuBPu9BsdKI4gzvj9Avrfsab9ZEAx7Mtn2Yqf0hwm0SCSNEYsYKdWuUEuvoNSeO 3RsxtDG29mjv75gVo+A6aobX75MMvEDDWwf2eIoRTbuBmOherT2e1LdY8nWyHpA/inO8FBjhY tzy3kAhfTihRSueDtz4Vm0St6VP8wqZ9yjD64Xs5OH56yUJgmD/TytBc0GfSq0Q1xBKTZgkyw gX/FPf82NWd9x5OdBrs0iOdMKmnS/O53/GuzXhXblwribYSv+LmZUnHIXbuvL2Pz0aLaMWXhb akuQ3qZ X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On Sat, 01 Sep 2018 18:18:01 +0100 Francis Wright wrote: > According to my reading of both the documentation for the function > random and its description in the manual, if it is called with no > argument then "the value might be any integer representable in Lisp, > i.e., an integer between =E2=80=98most-negative-fixnum=E2=80=99 and > =E2=80=98most-positive-fixnum=E2=80=99". Therefore, it should return a n= egative integer > half the time, but I have never yet seen it return a negative value. So > either the documentation or the implementation is wrong. For what it's > worth, I would prefer the documented behaviour over the current actual > behaviour. > > > In GNU Emacs 26.1 (build 1, x86_64-w64-mingw32) > of 2018-05-30 built on CIRROCUMULUS > Repository revision: 07f8f9bc5a51f5aa94eb099f3e15fbe0c20ea1ea > Windowing system distributor 'Microsoft Corp.', version 10.0.17134 Prompted by this report, I just ran `M-: (random)' twice, with these results: 1407814790132564328 (#o116114401367331100550, #x13899017bb648168) -5902216973509885 (#o-247600437205762375, #x-14f808fa17e4fd) This was on a build from current master under GNU/Linux Steve Berman From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: 26.1; (random) never returns negative Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 04 Sep 2018 22:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stephen Berman Cc: f.j.wright@live.co.uk, Francis Wright , 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.153610006721215 (code B ref 32605); Tue, 04 Sep 2018 22:28:01 +0000 Received: (at 32605) by debbugs.gnu.org; 4 Sep 2018 22:27:47 +0000 Received: from localhost ([127.0.0.1]:46093 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxJnX-0005W1-3B for submit@debbugs.gnu.org; Tue, 04 Sep 2018 18:27:47 -0400 Received: from mail-it0-f49.google.com ([209.85.214.49]:35131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxJnU-0005Vi-T0; Tue, 04 Sep 2018 18:27:45 -0400 Received: by mail-it0-f49.google.com with SMTP id 139-v6so6974816itf.0; Tue, 04 Sep 2018 15:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=KVprqR3pudYYT/vpuLZFW2YMG7WKsN988Hx/wJCsK3s=; b=V1ya7b6fq7ypzLT5XJ2azl7zq9qlXHsgm34GLYIObLQ3bIUcpcXEgZ5/HH74SAxZfI yukHOfEBv4hF+V/3BenY9TknOIs9QdVVzob0eYWF/E/QO1DcAOFph7qSfN1WHykYTzsu 3JSp6O8Fq8EM/R35pKBscVSRA9q5nwrZ3Pym2KGXsYA5fqO9DfMWq0fjwSF0Gpf8rfjb DfjPkALZLheqrsUXJMPbORJAFKD6h6p7nbSRCUg4EVlkGm+3UWExSr+cbfSPBWjGCq0r yh8FAYq4v0dLZW2JQzpbtLIBn4knE/eFggp0g911Pj+dSTrKgpcOao07D4oTcKQZGRQ/ hdpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=KVprqR3pudYYT/vpuLZFW2YMG7WKsN988Hx/wJCsK3s=; b=rouMqO2neIjSCRN6dEyG23W1xcpXDNgk4k4mGkhCZJ60ty9xfK2784guQS8dsNvSKV Z8yUYlcFjxH86ISxNRVmoAXj+cwQUE6wP2a0wSRETBVjNhOnBhsaJRegFnNoTgzAYPvm 2OHPkJHDmQYmiLB4jhc9lO8x8kvRGKy07O1XKqZL0qcdYof5oYZKzNW+ha9B0ciHCduq RpfmWW0bBnPpQQU1E/d/s5b/c+GDY9K0GM9IGM9yogJsyzUoEpWtCG0QBkksGpKoLATh g5T+GdIDk64Vt1qegEQhCGBKlDfxE2wieDGQHoIpAa90wXo8a+l6D7PhgqSO1o2gztNV RY9g== X-Gm-Message-State: APzg51BxxDoJjcPQjn8MVNV4G1biKbXwMKBs3uF+6xmXNvg66JXupbuN h28BDa0YmVdYun+iAfXI62/FX9A9 X-Google-Smtp-Source: ANB0VdaCYAOI8WywzQKCRo9Uf2+JzDp3inX1zpn9mOw7F51mNQU7NknGSwiZmNliJTr9Jqp8o4TugQ== X-Received: by 2002:a24:99c2:: with SMTP id a185-v6mr1945205ite.12.1536100059156; Tue, 04 Sep 2018 15:27:39 -0700 (PDT) Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id k1-v6sm19581ioh.21.2018.09.04.15.27.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Sep 2018 15:27:38 -0700 (PDT) From: Noam Postavsky References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> Date: Tue, 04 Sep 2018 18:27:37 -0400 In-Reply-To: <87zhx1ktp0.fsf@gmx.net> (Stephen Berman's message of "Sat, 01 Sep 2018 19:34:35 +0200") Message-ID: <87zhwwhp9i.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) retitle 32605 [w64] (random) never returns negative tags 32605 + confirmed quit Stephen Berman writes: > On Sat, 01 Sep 2018 18:18:01 +0100 Francis Wright wrote: >> Therefore, it should return a negative integer >> half the time, but I have never yet seen it return a negative value. >> In GNU Emacs 26.1 (build 1, x86_64-w64-mingw32) > Prompted by this report, I just ran `M-: (random)' twice, with these > results: > > 1407814790132564328 (#o116114401367331100550, #x13899017bb648168) > -5902216973509885 (#o-247600437205762375, #x-14f808fa17e4fd) > > This was on a build from current master under GNU/Linux This bug seems specific to 64 bit Windows builds. From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: 26.1; (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Sep 2018 13:22:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.153615367315272 (code B ref -1); Wed, 05 Sep 2018 13:22:01 +0000 Received: (at submit) by debbugs.gnu.org; 5 Sep 2018 13:21:13 +0000 Received: from localhost ([127.0.0.1]:46509 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxXk7-0003yD-NA for submit@debbugs.gnu.org; Wed, 05 Sep 2018 09:21:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46571) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fxXk5-0003y1-BX for submit@debbugs.gnu.org; Wed, 05 Sep 2018 09:21:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxXjz-0001MF-HZ for submit@debbugs.gnu.org; Wed, 05 Sep 2018 09:21:04 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_20,FREEMAIL_FROM autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:34348) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fxXjz-0001MB-E7 for submit@debbugs.gnu.org; Wed, 05 Sep 2018 09:21:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxXjy-0006OX-GZ for bug-gnu-emacs@gnu.org; Wed, 05 Sep 2018 09:21:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxXjv-0001H0-8J for bug-gnu-emacs@gnu.org; Wed, 05 Sep 2018 09:21:02 -0400 Received: from [195.159.176.226] (port=53974 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxXju-0001Eq-Vd for bug-gnu-emacs@gnu.org; Wed, 05 Sep 2018 09:20:59 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fxXhk-0008J6-ET for bug-gnu-emacs@gnu.org; Wed, 05 Sep 2018 15:18:44 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Wed, 05 Sep 2018 14:20:48 +0100 Lines: 29 Message-ID: References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@blaine.gmane.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (windows-nt) Cancel-Lock: sha1:9VXUFgOLyVyPiShivkyTJbhNZMQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.6 (----) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.6 (-----) On Tue 04 Sep 2018, Noam Postavsky wrote: > retitle 32605 [w64] (random) never returns negative > tags 32605 + confirmed > quit > > Stephen Berman writes: > >> On Sat, 01 Sep 2018 18:18:01 +0100 Francis Wright wrote: >>> Therefore, it should return a negative integer >>> half the time, but I have never yet seen it return a negative value. > >>> In GNU Emacs 26.1 (build 1, x86_64-w64-mingw32) > >> Prompted by this report, I just ran `M-: (random)' twice, with these >> results: >> >> 1407814790132564328 (#o116114401367331100550, #x13899017bb648168) >> -5902216973509885 (#o-247600437205762375, #x-14f808fa17e4fd) >> >> This was on a build from current master under GNU/Linux > > This bug seems specific to 64 bit Windows builds. ON 64bit Windows, sysdep.c sets RAND_BITS to 31, but random (in w32.c) only provides 30 bits. It looks like the mixing in get_random does not result in the top fixnum bit being set. AndyM From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Aug 2021 13:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Andy Moreton Cc: Eli Zaretskii , 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.162877428011869 (code B ref 32605); Thu, 12 Aug 2021 13:18:02 +0000 Received: (at 32605) by debbugs.gnu.org; 12 Aug 2021 13:18:00 +0000 Received: from localhost ([127.0.0.1]:37791 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEAau-00035N-Fl for submit@debbugs.gnu.org; Thu, 12 Aug 2021 09:18:00 -0400 Received: from quimby.gnus.org ([95.216.78.240]:40742) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEAas-000358-5p for 32605@debbugs.gnu.org; Thu, 12 Aug 2021 09:17:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wY+x3Xb0d5YU2THs0x0wLlucNW63vZUuz5omRiqYsLM=; b=MOxbfg6UdHsXEj1pd3uuUtxGni BYiAUZfOB9NqFS+C+8F3NGGpO33UyYeOR6yya6RaG0CkcFhaDr+zN/pL4j5jMqVQKf3BmHw6ttYLR GmqH5lwuPq79/S2t89l9P8nAW6ZTUCnkIZTxZGX0ia7sM1fMEQgIKjMzlOyfTraw4e0o=; Received: from [84.212.220.105] (helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mEAah-00067R-Nk; Thu, 12 Aug 2021 15:17:51 +0200 From: Lars Ingebrigtsen References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> Date: Thu, 12 Aug 2021 15:17:46 +0200 In-Reply-To: (Andy Moreton's message of "Wed, 05 Sep 2018 14:20:48 +0100") Message-ID: <87mtpmls3p.fsf_-_@gnus.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see @@CONTACT_ADDRESS@@ for details. Content preview: Andy Moreton writes: >> This bug seems specific to 64 bit Windows builds. > > ON 64bit Windows, sysdep.c sets RAND_BITS to 31, but random (in w32.c) > only provides 30 bits. It looks like the mixing in get_random does not [...] Content analysis details: (-2.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Andy Moreton writes: >> This bug seems specific to 64 bit Windows builds. > > ON 64bit Windows, sysdep.c sets RAND_BITS to 31, but random (in w32.c) > only provides 30 bits. It looks like the mixing in get_random does not > result in the top fixnum bit being set. So it's this: int random (void) { /* rand_as183 () gives us 15 random bits...hack together 30 bits. */ return ((rand_as183 () << 15) | rand_as183 ()); } So running rand_as183 and taking another bit from that might do the trick? Eli, do you have any comments here? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Aug 2021 13:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Lars Ingebrigtsen Cc: andrewjmoreton@gmail.com, 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.162877578722715 (code B ref 32605); Thu, 12 Aug 2021 13:44:02 +0000 Received: (at 32605) by debbugs.gnu.org; 12 Aug 2021 13:43:07 +0000 Received: from localhost ([127.0.0.1]:37855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEAz9-0005uF-9e for submit@debbugs.gnu.org; Thu, 12 Aug 2021 09:43:07 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33476) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEAz3-0005tg-HJ for 32605@debbugs.gnu.org; Thu, 12 Aug 2021 09:43:01 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:38006) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEAyy-0008UW-A0; Thu, 12 Aug 2021 09:42:52 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:4923 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEAyx-0002kz-TB; Thu, 12 Aug 2021 09:42:52 -0400 Date: Thu, 12 Aug 2021 16:42:35 +0300 Message-Id: <83o8a2dbjo.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87mtpmls3p.fsf_-_@gnus.org> (message from Lars Ingebrigtsen on Thu, 12 Aug 2021 15:17:46 +0200) References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Lars Ingebrigtsen > Cc: 32605@debbugs.gnu.org, Eli Zaretskii > Date: Thu, 12 Aug 2021 15:17:46 +0200 > > Andy Moreton writes: > > >> This bug seems specific to 64 bit Windows builds. > > > > ON 64bit Windows, sysdep.c sets RAND_BITS to 31, but random (in w32.c) > > only provides 30 bits. It looks like the mixing in get_random does not > > result in the top fixnum bit being set. > > So it's this: > > int > random (void) > { > /* rand_as183 () gives us 15 random bits...hack together 30 bits. */ > return ((rand_as183 () << 15) | rand_as183 ()); > } > > So running rand_as183 and taking another bit from that might do the > trick? Eli, do you have any comments here? The 'random' emulation in w32.c was never adapted to w64. Instead of calling rand_as183 one more time, perhaps it's better to trivially transform the value we have? Something like int val = ((rand_as183 () << 15) | rand_as183 ()); #ifdef __x86_64__ return 2 * val - 0x3FFFFFFF; #else return val; #endif Andy, can you test this, please? From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 Aug 2021 20:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16288004692103 (code B ref -1); Thu, 12 Aug 2021 20:35:02 +0000 Received: (at submit) by debbugs.gnu.org; 12 Aug 2021 20:34:29 +0000 Received: from localhost ([127.0.0.1]:39976 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEHPI-0000Xr-QK for submit@debbugs.gnu.org; Thu, 12 Aug 2021 16:34:29 -0400 Received: from lists.gnu.org ([209.51.188.17]:44750) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEHPE-0000Xg-IU for submit@debbugs.gnu.org; Thu, 12 Aug 2021 16:34:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEHPE-0003P6-2o for bug-gnu-emacs@gnu.org; Thu, 12 Aug 2021 16:34:24 -0400 Received: from ciao.gmane.io ([116.202.254.214]:37180) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEHPC-0002Zf-PN for bug-gnu-emacs@gnu.org; Thu, 12 Aug 2021 16:34:23 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mEHP8-0005Mg-UU for bug-gnu-emacs@gnu.org; Thu, 12 Aug 2021 22:34:18 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Thu, 12 Aug 2021 21:34:09 +0100 Message-ID: <86bl62s8qm.fsf@gmail.com> References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cancel-Lock: sha1:YTRi4jPGxkR4LaipcuNGAHzAxmY= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geb-bug-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.9 (/) On Thu 12 Aug 2021, Eli Zaretskii wrote: >> From: Lars Ingebrigtsen >> Cc: 32605@debbugs.gnu.org, Eli Zaretskii >> Date: Thu, 12 Aug 2021 15:17:46 +0200 >> >> Andy Moreton writes: >> >> >> This bug seems specific to 64 bit Windows builds. >> > >> > ON 64bit Windows, sysdep.c sets RAND_BITS to 31, but random (in w32.c) >> > only provides 30 bits. It looks like the mixing in get_random does not >> > result in the top fixnum bit being set. > > The 'random' emulation in w32.c was never adapted to w64. Surely real the problem is that RAND_BITS is 31, but the random() in w32.c does not provide 31 random bits (and thus fails to meet the API contract). In 32bit builds this problem is hidden because 30 bits are sufficient for a fixnum, so the value of bit30 in the result is ignored. On 64bit builds, 62 bits are needed for a fixnum, and trying to assemble a random number from multiple components does not work if RAND_BITS says 31 bits are usable, but the highest bit in that value is always zero. Also see > Instead of calling rand_as183 one more time, perhaps it's better to > trivially transform the value we have? Something like > > int val = ((rand_as183 () << 15) | rand_as183 ()); > #ifdef __x86_64__ > return 2 * val - 0x3FFFFFFF; > #else > return val; > #endif > > Andy, can you test this, please? That does not produce any negative random numbers within a reasonable number of attempts (a few dozen calls). Instead, calling rand_as183 again (as below) does produce positive and negative random numbers on 32bit and 64bit builds with a similar number of attempts: return ((rand_as183 () << 30) | (rand_as183 () << 15) | rand_as183 ()); While this may be less efficient, it at least meets the contract of providing 31 random bits. AndyM From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Aug 2021 06:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Andy Moreton Cc: 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.162883620226650 (code B ref 32605); Fri, 13 Aug 2021 06:31:02 +0000 Received: (at 32605) by debbugs.gnu.org; 13 Aug 2021 06:30:02 +0000 Received: from localhost ([127.0.0.1]:40395 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEQhe-0006vX-6F for submit@debbugs.gnu.org; Fri, 13 Aug 2021 02:30:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44610) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEQhb-0006up-Ot for 32605@debbugs.gnu.org; Fri, 13 Aug 2021 02:30:00 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:36880) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEQhW-0001WY-EU; Fri, 13 Aug 2021 02:29:54 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3096 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEQhW-0002hK-0B; Fri, 13 Aug 2021 02:29:54 -0400 Date: Fri, 13 Aug 2021 09:29:41 +0300 Message-Id: <83czqhdfhm.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <86bl62s8qm.fsf@gmail.com> (message from Andy Moreton on Thu, 12 Aug 2021 21:34:09 +0100) References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andy Moreton > Date: Thu, 12 Aug 2021 21:34:09 +0100 > > > int val = ((rand_as183 () << 15) | rand_as183 ()); > > #ifdef __x86_64__ > > return 2 * val - 0x3FFFFFFF; > > #else > > return val; > > #endif > > > > Andy, can you test this, please? > > That does not produce any negative random numbers within a reasonable > number of attempts (a few dozen calls). Thanks for testing. > Instead, calling rand_as183 again (as below) does produce positive and > negative random numbers on 32bit and 64bit builds with a similar number > of attempts: > > return ((rand_as183 () << 30) | (rand_as183 () << 15) | rand_as183 ()); > > While this may be less efficient, it at least meets the contract of > providing 31 random bits. What about the variant below, does it produce better results? int val = ((rand_as183 () << 15) | rand_as183 ()); #ifdef __x86_64__ return 2 * val - 0x7FFFFFFF; #else return val; #endif From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Aug 2021 21:13:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162888916822441 (code B ref -1); Fri, 13 Aug 2021 21:13:02 +0000 Received: (at submit) by debbugs.gnu.org; 13 Aug 2021 21:12:48 +0000 Received: from localhost ([127.0.0.1]:43137 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEeTv-0005ps-OR for submit@debbugs.gnu.org; Fri, 13 Aug 2021 17:12:47 -0400 Received: from lists.gnu.org ([209.51.188.17]:60844) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEeTq-0005pg-MR for submit@debbugs.gnu.org; Fri, 13 Aug 2021 17:12:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEeTq-0000FL-CW for bug-gnu-emacs@gnu.org; Fri, 13 Aug 2021 17:12:42 -0400 Received: from ciao.gmane.io ([116.202.254.214]:57540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEeTp-0001br-2o for bug-gnu-emacs@gnu.org; Fri, 13 Aug 2021 17:12:42 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mEeTl-0009AX-2g for bug-gnu-emacs@gnu.org; Fri, 13 Aug 2021 23:12:37 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Fri, 13 Aug 2021 22:12:29 +0100 Message-ID: <861r6xoxqa.fsf@gmail.com> References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cancel-Lock: sha1:zL2IYZM7/vzv4HBTkMHnscxxq0k= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geb-bug-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.9 (/) On Fri 13 Aug 2021, Eli Zaretskii wrote: >> From: Andy Moreton >> Date: Thu, 12 Aug 2021 21:34:09 +0100 >> >> > int val = ((rand_as183 () << 15) | rand_as183 ()); >> > #ifdef __x86_64__ >> > return 2 * val - 0x3FFFFFFF; >> > #else >> > return val; >> > #endif >> > >> > Andy, can you test this, please? >> >> That does not produce any negative random numbers within a reasonable >> number of attempts (a few dozen calls). > > Thanks for testing. You elided the detail of my previous message: Surely real the problem is that RAND_BITS is 31, but the random() in w32.c does not provide 31 random bits (and thus fails to meet the API contract). In 32bit builds this problem is hidden because 30 bits are sufficient for a fixnum, so the value of bit30 in the result is ignored. On 64bit builds, 62 bits are needed for a fixnum, and trying to assemble a random number from multiple components does not work if RAND_BITS says 31 bits are usable, but the highest bit in that value is always zero. Please answer that. This function appears to not work properly at all. >> Instead, calling rand_as183 again (as below) does produce positive and >> negative random numbers on 32bit and 64bit builds with a similar number >> of attempts: >> >> return ((rand_as183 () << 30) | (rand_as183 () << 15) | rand_as183 ()); >> >> While this may be less efficient, it at least meets the contract of >> providing 31 random bits. > > What about the variant below, does it produce better results? > > int val = ((rand_as183 () << 15) | rand_as183 ()); > #ifdef __x86_64__ > return 2 * val - 0x7FFFFFFF; > #else > return val; > #endif Why is this any better ? On 32bit builds it does not return 31 random bits (only a 30bit value) and on 64bit builds the lowest bit is not random. I'm not sure I see the point of this bit manipulation as it does not spread randomness throughout the bits in the returned value. AndyM From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 05:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Andy Moreton Cc: 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.16289205246322 (code B ref 32605); Sat, 14 Aug 2021 05:56:02 +0000 Received: (at 32605) by debbugs.gnu.org; 14 Aug 2021 05:55:24 +0000 Received: from localhost ([127.0.0.1]:43422 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEmdg-0001du-Kd for submit@debbugs.gnu.org; Sat, 14 Aug 2021 01:55:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:44270) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEmdc-0001df-GB for 32605@debbugs.gnu.org; Sat, 14 Aug 2021 01:55:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:42746) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEmdX-0004bH-7p; Sat, 14 Aug 2021 01:55:15 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1893 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEmdN-0001xL-KU; Sat, 14 Aug 2021 01:55:15 -0400 Date: Sat, 14 Aug 2021 08:54:53 +0300 Message-Id: <83sfzcbmfm.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <861r6xoxqa.fsf@gmail.com> (message from Andy Moreton on Fri, 13 Aug 2021 22:12:29 +0100) References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andy Moreton > Date: Fri, 13 Aug 2021 22:12:29 +0100 > > You elided the detail of my previous message: Because I had nothing useful to say in response. If someone wants to work on a better emulation of 'random' for w64, that's fine; I don't consider myself an expert in this area, and therefore not sure I even understand the significance of providing 31 bits of randomness from a functions such as 'random', which AFAIR is not the standard of RNGs. My goal was to make the current implementation better with relatively simple and straightforward changes. Calling rand_as183 one more time is IMHO not a good solution; but again, I'm not an expert. > > What about the variant below, does it produce better results? > > > > int val = ((rand_as183 () << 15) | rand_as183 ()); > > #ifdef __x86_64__ > > return 2 * val - 0x7FFFFFFF; > > #else > > return val; > > #endif > > Why is this any better ? On 32bit builds it does not return 31 random > bits (only a 30bit value) and on 64bit builds the lowest bit is not > random. I hoped it will be better because it produced negative values as well, not only positive values, without any performance penalty. For a problem that was left unsolved for 3 years it sounds good enough to me. So my proposal is to install the above until someone comes up with a better solution. But if that's unacceptable, let alone if my participation in this discussion is an annoyance, like it seems to be, I'll readily bow out of it. From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 08:32:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162892988321651 (code B ref -1); Sat, 14 Aug 2021 08:32:01 +0000 Received: (at submit) by debbugs.gnu.org; 14 Aug 2021 08:31:23 +0000 Received: from localhost ([127.0.0.1]:43515 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEp4d-0005d9-BT for submit@debbugs.gnu.org; Sat, 14 Aug 2021 04:31:23 -0400 Received: from lists.gnu.org ([209.51.188.17]:48020) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEp4a-0005cz-20 for submit@debbugs.gnu.org; Sat, 14 Aug 2021 04:31:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEp4Y-0006t5-Oz for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 04:31:19 -0400 Received: from ciao.gmane.io ([116.202.254.214]:35836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEp4W-0008Rv-Jl for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 04:31:18 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mEp4T-0005qX-QQ for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 10:31:13 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Sat, 14 Aug 2021 09:31:06 +0100 Message-ID: <86mtpksa0l.fsf@gmail.com> References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cancel-Lock: sha1:agTNNJIL25tRJpafpya5+yoSNgw= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geb-bug-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.9 (/) On Sat 14 Aug 2021, Eli Zaretskii wrote: >> From: Andy Moreton >> Date: Fri, 13 Aug 2021 22:12:29 +0100 >> >> You elided the detail of my previous message: > > Because I had nothing useful to say in response. If someone wants to > work on a better emulation of 'random' for w64, that's fine; I don't > consider myself an expert in this area, and therefore not sure I even > understand the significance of providing 31 bits of randomness from a > functions such as 'random', which AFAIR is not the standard of RNGs. > My goal was to make the current implementation better with relatively > simple and straightforward changes. Calling rand_as183 one more time > is IMHO not a good solution; but again, I'm not an expert. Please look at get_random() in sysdep.c: it constructs wider random numbers by concatenating random bits from calling random() in a loop, and expects that the result of each call in that loop returns RAND_BITS (defined in sysdep.c as 31 on this platform). The random() replacement in w32.c does not meet this contract, as it only provides 30 bits, causing get_random() to produce a concatenated result containing bits with fixed, non-random values. >> > What about the variant below, does it produce better results? >> > >> > int val = ((rand_as183 () << 15) | rand_as183 ()); >> > #ifdef __x86_64__ >> > return 2 * val - 0x7FFFFFFF; >> > #else >> > return val; >> > #endif >> >> Why is this any better ? On 32bit builds it does not return 31 random >> bits (only a 30bit value) and on 64bit builds the lowest bit is not >> random. > > I hoped it will be better because it produced negative values as well, > not only positive values, without any performance penalty. For a > problem that was left unsolved for 3 years it sounds good enough to > me. There doesn't seem to be any point in making changes if they disguise a bug rather than fixing it. Your proposal just changes which bits in the the result are non-random. > So my proposal is to install the above until someone comes up with a > better solution. But if that's unacceptable, let alone if my > participation in this discussion is an annoyance, like it seems to be, > I'll readily bow out of it. As far as I can see the way to fix this is one of: a) Fix random() in w32.c to return a 31 bit random number. b) Modify the logic in sysdep.c that defines RAND_BITS to set it to 30 on this platform, so get_random() produces working results. The get_random() loop would then need one call to random on 32bit builds (FIXNUM_BITS is 30), and three on 64bit builds (FIXNUM_BITS is 62). I'm not an expert on random numbers either, and your efforts are not an annoyance, but I am puzzled why you so strongly prize performance over correctness in this instance. AndyM From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 08:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Andy Moreton Cc: 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.162893144423969 (code B ref 32605); Sat, 14 Aug 2021 08:58:01 +0000 Received: (at 32605) by debbugs.gnu.org; 14 Aug 2021 08:57:24 +0000 Received: from localhost ([127.0.0.1]:43530 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEpTo-0006EX-74 for submit@debbugs.gnu.org; Sat, 14 Aug 2021 04:57:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEpTj-0006EH-KL for 32605@debbugs.gnu.org; Sat, 14 Aug 2021 04:57:22 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:45766) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEpTe-0001Rl-A8; Sat, 14 Aug 2021 04:57:14 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1256 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEpTd-00048y-Qx; Sat, 14 Aug 2021 04:57:14 -0400 Date: Sat, 14 Aug 2021 11:57:01 +0300 Message-Id: <83a6lkbe02.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <86mtpksa0l.fsf@gmail.com> (message from Andy Moreton on Sat, 14 Aug 2021 09:31:06 +0100) References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andy Moreton > Date: Sat, 14 Aug 2021 09:31:06 +0100 > > I'm not an expert on random numbers either, and your efforts are not an > annoyance, but I am puzzled why you so strongly prize performance over > correctness in this instance. Because I have no idea how important the "correctness" part is, or why. OTOH, this stuff, when used, tends to be in the inner loops, so performance matters. From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 11:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162893917921743 (code B ref -1); Sat, 14 Aug 2021 11:07:01 +0000 Received: (at submit) by debbugs.gnu.org; 14 Aug 2021 11:06:19 +0000 Received: from localhost ([127.0.0.1]:43661 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mErUZ-0005ed-5i for submit@debbugs.gnu.org; Sat, 14 Aug 2021 07:06:19 -0400 Received: from lists.gnu.org ([209.51.188.17]:43336) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mErUW-0005eV-TZ for submit@debbugs.gnu.org; Sat, 14 Aug 2021 07:06:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mErUW-00020W-OD for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 07:06:16 -0400 Received: from ciao.gmane.io ([116.202.254.214]:50776) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mErUS-0006Yf-1V for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 07:06:13 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mErUP-0009ts-NW for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 13:06:09 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Sat, 14 Aug 2021 12:06:00 +0100 Message-ID: <86sfzcjnfr.fsf@gmail.com> References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cancel-Lock: sha1:Xa01Ld8fj+zt1+qoI2gRqfO2oA4= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geb-bug-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.9 (/) On Sat 14 Aug 2021, Eli Zaretskii wrote: >> From: Andy Moreton >> Date: Sat, 14 Aug 2021 09:31:06 +0100 >> >> I'm not an expert on random numbers either, and your efforts are not an >> annoyance, but I am puzzled why you so strongly prize performance over >> correctness in this instance. > > Because I have no idea how important the "correctness" part is, or > why. OTOH, this stuff, when used, tends to be in the inner loops, so > performance matters. I doubt anyone expects cryptographic quality randomness or any given statistical distribution from such a general purpose routine, but they have a reasonable expectation that the results from 'get_random' do not have stuck bits that are always non-random. In which case perhaps the solution is to change the RAND_BITS logic in sysdep.c on Windows to override the RAND_BITS definition: + #ifdef WINDOWSNT + /* Use w32.c replacement for random(). */ + # define RAND_BITS 15 + #endif #ifndef RAND_BITS # ifdef HAVE_RANDOM # define RAND_BITS 31 # else /* !HAVE_RANDOM */ ... #endif ..and then in w32.c make 'random' return the 15bit value from 'rand_as183': int random (void) { /* rand_as183 () gives us 15 random bits. */ return rand_as183 (); } That should result in 'get_random' receiving 15 bits of randomness in each loop iteration and thus computing a valid result. [This could obviously be optimised to open code 'rand_as183' in 'random', or allow the compiler to inline it by moving the w32.c implementations of 'random' and 'srandom' into sysdep.c] As 'get_random_bignum' (in fns.c) calls 'get_random' in a loop, that should also remove bugs from that function on this platform. Perhaps this would be helped by having a test for 'get_random', to check that every bit of a fixnum is toggled after a reasonable number of calls. While that does not test the statistical distribution of the random number sequence, it would ensure that the values returned by 'get_random' are not always positive, or always even, etc. AndyM From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 11:34:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Andy Moreton Cc: 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.1628940797503 (code B ref 32605); Sat, 14 Aug 2021 11:34:02 +0000 Received: (at 32605) by debbugs.gnu.org; 14 Aug 2021 11:33:17 +0000 Received: from localhost ([127.0.0.1]:43690 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEruf-000083-HB for submit@debbugs.gnu.org; Sat, 14 Aug 2021 07:33:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33096) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mErue-00007d-4N for 32605@debbugs.gnu.org; Sat, 14 Aug 2021 07:33:16 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:48056) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEruY-00089O-UJ; Sat, 14 Aug 2021 07:33:10 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2864 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEruX-0001wS-QG; Sat, 14 Aug 2021 07:33:10 -0400 Date: Sat, 14 Aug 2021 14:33:00 +0300 Message-Id: <835yw8b6s3.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <86sfzcjnfr.fsf@gmail.com> (message from Andy Moreton on Sat, 14 Aug 2021 12:06:00 +0100) References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> <86sfzcjnfr.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andy Moreton > Date: Sat, 14 Aug 2021 12:06:00 +0100 > > >> I'm not an expert on random numbers either, and your efforts are not an > >> annoyance, but I am puzzled why you so strongly prize performance over > >> correctness in this instance. > > > > Because I have no idea how important the "correctness" part is, or > > why. OTOH, this stuff, when used, tends to be in the inner loops, so > > performance matters. > > I doubt anyone expects cryptographic quality randomness or any given > statistical distribution from such a general purpose routine, but they > have a reasonable expectation that the results from 'get_random' do not > have stuck bits that are always non-random. > > In which case perhaps the solution is to change the RAND_BITS logic > in sysdep.c on Windows to override the RAND_BITS definition: > > + #ifdef WINDOWSNT > + /* Use w32.c replacement for random(). */ > + # define RAND_BITS 15 > + #endif > > #ifndef RAND_BITS > # ifdef HAVE_RANDOM > # define RAND_BITS 31 > # else /* !HAVE_RANDOM */ > ... > #endif > > ..and then in w32.c make 'random' return the 15bit value from > 'rand_as183': Why not keep the 30 bits we produce today on 32-bit builds? From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 12:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16289430234020 (code B ref -1); Sat, 14 Aug 2021 12:11:01 +0000 Received: (at submit) by debbugs.gnu.org; 14 Aug 2021 12:10:23 +0000 Received: from localhost ([127.0.0.1]:43753 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEsUZ-00012m-Jr for submit@debbugs.gnu.org; Sat, 14 Aug 2021 08:10:23 -0400 Received: from lists.gnu.org ([209.51.188.17]:34342) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEsUX-00012e-Di for submit@debbugs.gnu.org; Sat, 14 Aug 2021 08:10:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEsUW-0004I5-Q6 for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 08:10:21 -0400 Received: from ciao.gmane.io ([116.202.254.214]:58232) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEsUV-00046f-Gy for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 08:10:20 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mEsUS-0002S2-U1 for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 14:10:16 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Sat, 14 Aug 2021 13:10:08 +0100 Message-ID: <86fsvcz0pr.fsf@gmail.com> References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> <86sfzcjnfr.fsf@gmail.com> <835yw8b6s3.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cancel-Lock: sha1:XDr7l4Sjj0jCkBmjtmGR6cKxMcI= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geb-bug-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.9 (/) On Sat 14 Aug 2021, Eli Zaretskii wrote: >> From: Andy Moreton >> Date: Sat, 14 Aug 2021 12:06:00 +0100 >> >> >> I'm not an expert on random numbers either, and your efforts are not an >> >> annoyance, but I am puzzled why you so strongly prize performance over >> >> correctness in this instance. >> > >> > Because I have no idea how important the "correctness" part is, or >> > why. OTOH, this stuff, when used, tends to be in the inner loops, so >> > performance matters. >> >> I doubt anyone expects cryptographic quality randomness or any given >> statistical distribution from such a general purpose routine, but they >> have a reasonable expectation that the results from 'get_random' do not >> have stuck bits that are always non-random. >> >> In which case perhaps the solution is to change the RAND_BITS logic >> in sysdep.c on Windows to override the RAND_BITS definition: >> >> + #ifdef WINDOWSNT >> + /* Use w32.c replacement for random(). */ >> + # define RAND_BITS 15 >> + #endif >> >> #ifndef RAND_BITS >> # ifdef HAVE_RANDOM >> # define RAND_BITS 31 >> # else /* !HAVE_RANDOM */ >> ... >> #endif >> >> ..and then in w32.c make 'random' return the 15bit value from >> 'rand_as183': > > Why not keep the 30 bits we produce today on 32-bit builds? For 32bit builds (FIXNUM_BITS is 30), either: a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice. 'get_random' needs 1 call to 'random' (total 2 calls of 'rand_as183'). b) define RAND_BITS to 15, 'random' calls 'rand_as183' once. 'get_random' needs 2 calls to 'random' (total 2 calls of 'rand_as183'). For 64bit builds (FIXNUM_BITS is 62), either: a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice. 'get_random' needs 3 calls to 'random' (total 6 calls of 'rand_as183'). b) define RAND_BITS to 15, 'random' calls 'rand_as183' once. 'get_random' needs 4 calls to 'random' (total 4 calls of 'rand_as183'). On 32bit builds both options are roughly equivalent. On 64bit builds option (b) is better as option (a) does unnecessary work. AndyM From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 12:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Andy Moreton Cc: 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.162894459123311 (code B ref 32605); Sat, 14 Aug 2021 12:37:01 +0000 Received: (at 32605) by debbugs.gnu.org; 14 Aug 2021 12:36:31 +0000 Received: from localhost ([127.0.0.1]:43789 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEstr-00063v-IR for submit@debbugs.gnu.org; Sat, 14 Aug 2021 08:36:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40734) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEsto-00063e-Dt for 32605@debbugs.gnu.org; Sat, 14 Aug 2021 08:36:29 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49452) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEsti-00047x-HM; Sat, 14 Aug 2021 08:36:23 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2943 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEsti-0006SC-3E; Sat, 14 Aug 2021 08:36:22 -0400 Date: Sat, 14 Aug 2021 15:36:09 +0300 Message-Id: <834kbsb3uu.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <86fsvcz0pr.fsf@gmail.com> (message from Andy Moreton on Sat, 14 Aug 2021 13:10:08 +0100) References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> <86sfzcjnfr.fsf@gmail.com> <835yw8b6s3.fsf@gnu.org> <86fsvcz0pr.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andy Moreton > Date: Sat, 14 Aug 2021 13:10:08 +0100 > > > Why not keep the 30 bits we produce today on 32-bit builds? > > For 32bit builds (FIXNUM_BITS is 30), either: > > a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice. > 'get_random' needs 1 call to 'random' (total 2 calls of 'rand_as183'). > > b) define RAND_BITS to 15, 'random' calls 'rand_as183' once. > 'get_random' needs 2 calls to 'random' (total 2 calls of 'rand_as183'). > > For 64bit builds (FIXNUM_BITS is 62), either: > > a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice. > 'get_random' needs 3 calls to 'random' (total 6 calls of 'rand_as183'). > > b) define RAND_BITS to 15, 'random' calls 'rand_as183' once. > 'get_random' needs 4 calls to 'random' (total 4 calls of 'rand_as183'). > > On 32bit builds both options are roughly equivalent. > On 64bit builds option (b) is better as option (a) does unnecessary work. The above assumes we will never call 'random' except via 'get_random'. Is that something we want to bet on? From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 13:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16289484504959 (code B ref -1); Sat, 14 Aug 2021 13:41:01 +0000 Received: (at submit) by debbugs.gnu.org; 14 Aug 2021 13:40:50 +0000 Received: from localhost ([127.0.0.1]:43855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEtu6-0001Hv-C8 for submit@debbugs.gnu.org; Sat, 14 Aug 2021 09:40:50 -0400 Received: from lists.gnu.org ([209.51.188.17]:34142) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEtu5-0001Ho-7V for submit@debbugs.gnu.org; Sat, 14 Aug 2021 09:40:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEtu4-0008Sp-Tx for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 09:40:48 -0400 Received: from ciao.gmane.io ([116.202.254.214]:36804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEtu0-0002C2-J5 for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 09:40:48 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mEtty-000445-IR for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 15:40:42 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Sat, 14 Aug 2021 14:40:35 +0100 Message-ID: <86a6lkywj0.fsf@gmail.com> References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> <86sfzcjnfr.fsf@gmail.com> <835yw8b6s3.fsf@gnu.org> <86fsvcz0pr.fsf@gmail.com> <834kbsb3uu.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cancel-Lock: sha1:7AyM3GOISTdfQdHEjcV9C7VYvWo= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geb-bug-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.9 (/) On Sat 14 Aug 2021, Eli Zaretskii wrote: >> From: Andy Moreton >> Date: Sat, 14 Aug 2021 13:10:08 +0100 >> >> > Why not keep the 30 bits we produce today on 32-bit builds? >> >> For 32bit builds (FIXNUM_BITS is 30), either: >> >> a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice. >> 'get_random' needs 1 call to 'random' (total 2 calls of 'rand_as183'). >> >> b) define RAND_BITS to 15, 'random' calls 'rand_as183' once. >> 'get_random' needs 2 calls to 'random' (total 2 calls of 'rand_as183'). >> >> For 64bit builds (FIXNUM_BITS is 62), either: >> >> a) define RAND_BITS to 30, 'random' calls 'rand_as183' twice. >> 'get_random' needs 3 calls to 'random' (total 6 calls of 'rand_as183'). >> >> b) define RAND_BITS to 15, 'random' calls 'rand_as183' once. >> 'get_random' needs 4 calls to 'random' (total 4 calls of 'rand_as183'). >> >> On 32bit builds both options are roughly equivalent. >> On 64bit builds option (b) is better as option (a) does unnecessary work. > > The above assumes we will never call 'random' except via 'get_random'. > Is that something we want to bet on? Option (b) fixes bugs in the current code. Currently 'get_random' is the only caller of 'random'. If inefficiency is a problem after later code changes, then then this issue can be revisited. Another option is to replace the imlementation of 'random' in w32.c with a different PRNG that can generate 31 bits more efficiently than using 3 calls to 'rand_as183'. Yet another possibility is to use 'getrandom' from gnulib instead of all of this Windows specific code, but that may bring a fresh set of concerns to be considered. AndyM From unknown Thu Sep 11 17:28:31 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: f.j.wright@live.co.uk Subject: bug#32605: closed (Re: bug#32605: [w64] (random) never returns negative) Message-ID: References: <831r6waxz6.fsf@gnu.org> <855zzpf86u.fsf@gmail.com> X-Gnu-PR-Message: they-closed 32605 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: confirmed Reply-To: 32605@debbugs.gnu.org Date: Sat, 14 Aug 2021 14:44:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1628952242-13325-1" This is a multi-part message in MIME format... ------------=_1628952242-13325-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #32605: [w64] (random) never returns negative which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 32605@debbugs.gnu.org. --=20 32605: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D32605 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1628952242-13325-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 32605-done) by debbugs.gnu.org; 14 Aug 2021 14:43:35 +0000 Received: from localhost ([127.0.0.1]:45274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEuso-0003SB-Vo for submit@debbugs.gnu.org; Sat, 14 Aug 2021 10:43:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38178) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEusi-0003Rt-BD for 32605-done@debbugs.gnu.org; Sat, 14 Aug 2021 10:43:33 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:51884) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mEusc-0004aE-T3; Sat, 14 Aug 2021 10:43:22 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:2789 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEusc-0004aG-Ch; Sat, 14 Aug 2021 10:43:22 -0400 Date: Sat, 14 Aug 2021 17:43:09 +0300 Message-Id: <831r6waxz6.fsf@gnu.org> From: Eli Zaretskii To: Andy Moreton In-Reply-To: <86a6lkywj0.fsf@gmail.com> (message from Andy Moreton on Sat, 14 Aug 2021 14:40:35 +0100) Subject: Re: bug#32605: [w64] (random) never returns negative References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> <86sfzcjnfr.fsf@gmail.com> <835yw8b6s3.fsf@gnu.org> <86fsvcz0pr.fsf@gmail.com> <834kbsb3uu.fsf@gnu.org> <86a6lkywj0.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 32605-done Cc: 32605-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andy Moreton > Date: Sat, 14 Aug 2021 14:40:35 +0100 > > >> On 32bit builds both options are roughly equivalent. > >> On 64bit builds option (b) is better as option (a) does unnecessary work. > > > > The above assumes we will never call 'random' except via 'get_random'. > > Is that something we want to bet on? > > Option (b) fixes bugs in the current code. Currently 'get_random' is the > only caller of 'random'. If inefficiency is a problem after later code > changes, then then this issue can be revisited. > > Another option is to replace the imlementation of 'random' in w32.c with > a different PRNG that can generate 31 bits more efficiently than using 3 > calls to 'rand_as183'. > > Yet another possibility is to use 'getrandom' from gnulib instead of all > of this Windows specific code, but that may bring a fresh set of > concerns to be considered. Thanks, I've decided to go with a hybrid approach that doesn't change how 32-bit builds behaved up to now. ------------=_1628952242-13325-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 1 Sep 2018 17:20:54 +0000 Received: from localhost ([127.0.0.1]:42076 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fw9Zu-0000XM-33 for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:54 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48463) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fw9Zt-0000X8-86 for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fw9Zi-0000vj-DK for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:45 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:45762) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fw9Zi-0000vT-3i for submit@debbugs.gnu.org; Sat, 01 Sep 2018 13:20:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fw9Ze-0001EW-L2 for bug-gnu-emacs@gnu.org; Sat, 01 Sep 2018 13:20:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fw9XB-0007i5-EX for bug-gnu-emacs@gnu.org; Sat, 01 Sep 2018 13:18:08 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:40209) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fw9XB-0007gg-7L for bug-gnu-emacs@gnu.org; Sat, 01 Sep 2018 13:18:05 -0400 Received: by mail-wr1-x42f.google.com with SMTP id n2-v6so13940832wrw.7 for ; Sat, 01 Sep 2018 10:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:reply-to:date:message-id:mime-version :content-transfer-encoding; bh=FsyHN41X96cC5fbiGYElqlMCmgnAQrpErD6+opD2St0=; b=tZJ/yMRyHQ3vobEELRCpds03mO4rDFVSDJpJ+zzzttYNxd65+kUqkaaVinYoUUmKNQ NK2+NX1/SI6+L9Pn+Od44aJlNvBw8LzY2b3+DYAw3Gh0RnqWSGkVUhqfABodtcXs3oek XPfvm7N8OOKXRGlrLNccNO+x00PUWBuRt8FYzW/UXUjrOFCyTqA2/5NWPHkjVHXcUBGr Q9OZD0vqAgmbOkynF1Zn9H7gCHdifBsLi++fd0yUrIwZUfgGGzCgKtjWgkoPtdbnpf8O svfdDWvHfVhp6374cy/huocNEjfdP1+IoQnc7UnQXQ6Br/B3UCR9yy+nMJjzilemjGd1 8iEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:reply-to:date:message-id :mime-version:content-transfer-encoding; bh=FsyHN41X96cC5fbiGYElqlMCmgnAQrpErD6+opD2St0=; b=Z8Vz2fZcFgrg1eAoXv8Ij3BZhOTR1v3WDk0u74lWZLDMPHRHDkOncDUCVqFRF+W+Do IsMxWWNU7XkbzHmU7AsCb6floLqOJy/1NOS4pB23l2ULn28AOANoN6Lh19u2EWOkpnOE 72UrjU8zbUtStqR5tyuljnnlk2xMglq2tktuyRJHJyuKsNi40QZZnxojBlRDyvuLajn+ x7dmNLqyd4AZU0GRa4h4vO30zgHZXexRWhYBpdd6eeO3cLpg6cbFLJfC8v7ZVrANqUaD DbCTdR8MrlByOZ057Axjr2WsaZPGk7d+4Vpx5w9+55uWJBVvh4luBw53udFo5PFDchsx 6Nzg== X-Gm-Message-State: APzg51CMMU22C9/Y5fjaD1I8tHN456DWIge7ZQHwEC7fvfzDkTtnJIow RnLuGvKWS9ZTqlq2LgtVp7XRBVqe X-Google-Smtp-Source: ANB0VdZrffPm2KmlnC3947QdAFyqhY6mM35Kbb8bmPpAFe+f/4zlUz9pRR+2HcxPVTmmx87xt+OE9g== X-Received: by 2002:adf:d84a:: with SMTP id k10-v6mr13276579wrl.26.1535822283371; Sat, 01 Sep 2018 10:18:03 -0700 (PDT) Received: from Monolith (host-92-19-191-141.as13285.net. [92.19.191.141]) by smtp.gmail.com with ESMTPSA id 75-v6sm15810157wml.21.2018.09.01.10.18.02 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 01 Sep 2018 10:18:02 -0700 (PDT) From: Francis Wright To: bug-gnu-emacs@gnu.org Subject: 26.1; (random) never returns negative Date: Sat, 01 Sep 2018 18:18:01 +0100 Message-ID: <855zzpf86u.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=gb2312 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: f.j.wright@live.co.uk Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) According to my reading of both the documentation for the function random and its description in the manual, if it is called with no argument then "the value might be any integer representable in Lisp, i.e., an integer between =A1=AEmost-negative-fixnum=A1=AF and =A1=AEmost-positive-fixnum=A1=AF". Therefore, it should return a negative = integer half the time, but I have never yet seen it return a negative value. So either the documentation or the implementation is wrong. For what it's worth, I would prefer the documented behaviour over the current actual behaviour. In GNU Emacs 26.1 (build 1, x86_64-w64-mingw32) of 2018-05-30 built on CIRROCUMULUS Repository revision: 07f8f9bc5a51f5aa94eb099f3e15fbe0c20ea1ea Windowing system distributor 'Microsoft Corp.', version 10.0.17134 Recent messages: Canceling debug-on-entry for all functions You can run the command =A1=AEcancel-debug-on-entry=A1=AF with M-x ca-d-e R= ET Canceling debug-on-entry for all functions 1515484088033472457 / 2067076301065092720 t [2 times] Mark set [2 times] Saving file c:/Users/fjw/REDUCE@SourceForge/emacs/REDUCE/Big Integer Suppor= t/eslbigint.el... Wrote c:/Users/fjw/REDUCE@SourceForge/emacs/REDUCE/Big Integer Support/eslb= igint.el Type "q" in help window to restore its previous buffer. mwheel-scroll: End of buffer [6 times] mwheel-scroll: Beginning of buffer [9 times] Configured using: 'configure --without-dbus --host=3Dx86_64-w64-mingw32 --without-compress-install 'CFLAGS=3D-O2 -static -g3'' Configured features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS LCMS2 Important settings: value of $LANG: ENG locale-coding-system: cp1252 Major mode: Info Minor modes in effect: diff-auto-refine-mode: t shell-dirtrack-mode: t show-paren-mode: t delete-selection-mode: t electric-pair-mode: t tooltip-mode: t global-eldoc-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t buffer-read-only: t line-number-mode: t transient-mark-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message rmc puny rfc822 mml mml-sec epa derived epg gnus-util rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils info eieio-opt speedbar sb-image ezimage dframe find-func help-fns radix-tree cl-extra thingatpt misearch multi-isearch edebug reposition time-stamp help-mode cl-print debug vc-git diff-mode easy-mmode vc-dispatcher vc-svn dired dired-loaddefs flyspell ispell imenu tramp tramp-compat tramp-loaddefs trampver ucs-normalize shell pcomplete comint ansi-color ring parse-time format-spec advice paren delsel cus-start cus-load finder-inf package easymenu epg-config url-handlers url-parse auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs password-cache url-vars seq byte-opt gv bytecomp byte-compile cconv cl-loaddefs cl-lib elec-pair server time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks lisp-float-type mwheel dos-w32 ls-lisp disp-table term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode elisp-mode lisp-mode prog-mode register page menu-bar rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock syntax facemenu font-core term/tty-colors frame cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite charscript charprop case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice loaddefs button faces cus-face macroexp files text-properties overlay sha1 md5 base64 format env code-pages mule custom widget hashtable-print-readable backquote w32notify w32 lcms2 multi-tty make-network-process emacs) Memory information: ((conses 16 277958 12135) (symbols 56 26263 1) (miscs 48 215 603) (strings 32 53052 3399) (string-bytes 1 1403187) (vectors 16 43081) (vector-slots 8 801770 16514) (floats 8 79 425) (intervals 56 1601 17) (buffers 992 18)) ------------=_1628952242-13325-1-- From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative In-Reply-To: <855zzpf86u.fsf@gmail.com> Resent-From: Andy Moreton Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Aug 2021 18:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: 32605@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16289668556849 (code B ref -1); Sat, 14 Aug 2021 18:48:02 +0000 Received: (at submit) by debbugs.gnu.org; 14 Aug 2021 18:47:35 +0000 Received: from localhost ([127.0.0.1]:45400 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEygx-0001mP-DT for submit@debbugs.gnu.org; Sat, 14 Aug 2021 14:47:35 -0400 Received: from lists.gnu.org ([209.51.188.17]:37830) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mEygs-0001mE-Qk for submit@debbugs.gnu.org; Sat, 14 Aug 2021 14:47:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEygs-0005SP-IH for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 14:47:30 -0400 Received: from ciao.gmane.io ([116.202.254.214]:33314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mEygr-0001Gt-5A for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 14:47:30 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1mEygp-00011V-2o for bug-gnu-emacs@gnu.org; Sat, 14 Aug 2021 20:47:27 +0200 X-Injected-Via-Gmane: http://gmane.org/ From: Andy Moreton Date: Sat, 14 Aug 2021 19:47:22 +0100 Message-ID: <86h7framo5.fsf@gmail.com> References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> <86sfzcjnfr.fsf@gmail.com> <835yw8b6s3.fsf@gnu.org> <86fsvcz0pr.fsf@gmail.com> <834kbsb3uu.fsf@gnu.org> <86a6lkywj0.fsf@gmail.com> <831r6waxz6.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (windows-nt) Cancel-Lock: sha1:m0E+C1UnH3prhuw9rlNgOAv6UJk= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geb-bug-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.1 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.9 (/) On Sat 14 Aug 2021, Eli Zaretskii wrote: >> From: Andy Moreton >> Date: Sat, 14 Aug 2021 14:40:35 +0100 >> >> >> On 32bit builds both options are roughly equivalent. >> >> On 64bit builds option (b) is better as option (a) does unnecessary work. >> > >> > The above assumes we will never call 'random' except via 'get_random'. >> > Is that something we want to bet on? >> >> Option (b) fixes bugs in the current code. Currently 'get_random' is the >> only caller of 'random'. If inefficiency is a problem after later code >> changes, then then this issue can be revisited. >> >> Another option is to replace the imlementation of 'random' in w32.c with >> a different PRNG that can generate 31 bits more efficiently than using 3 >> calls to 'rand_as183'. >> >> Yet another possibility is to use 'getrandom' from gnulib instead of all >> of this Windows specific code, but that may bring a fresh set of >> concerns to be considered. > > Thanks, I've decided to go with a hybrid approach that doesn't change > how 32-bit builds behaved up to now. That looks fine, and the bug reported by the OP now appears fixed in testing on 32bit and 64bit builds. AndyM From unknown Thu Sep 11 17:28:31 2025 X-Loop: help-debbugs@gnu.org Subject: bug#32605: [w64] (random) never returns negative Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Aug 2021 06:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32605 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed To: Andy Moreton Cc: 32605@debbugs.gnu.org Received: via spool by 32605-submit@debbugs.gnu.org id=B32605.16290076654886 (code B ref 32605); Sun, 15 Aug 2021 06:08:01 +0000 Received: (at 32605) by debbugs.gnu.org; 15 Aug 2021 06:07:45 +0000 Received: from localhost ([127.0.0.1]:45627 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mF9JB-0001Gj-Ax for submit@debbugs.gnu.org; Sun, 15 Aug 2021 02:07:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47528) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mF9J7-0001GT-3j for 32605@debbugs.gnu.org; Sun, 15 Aug 2021 02:07:44 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:41456) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mF9J2-0007zh-0D; Sun, 15 Aug 2021 02:07:36 -0400 Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:3868 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mF9J1-0004Ww-KF; Sun, 15 Aug 2021 02:07:35 -0400 Date: Sun, 15 Aug 2021 09:07:25 +0300 Message-Id: <83v9479r6q.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <86h7framo5.fsf@gmail.com> (message from Andy Moreton on Sat, 14 Aug 2021 19:47:22 +0100) References: <855zzpf86u.fsf@gmail.com> <87zhx1ktp0.fsf@gmx.net> <87zhwwhp9i.fsf@gmail.com> <87mtpmls3p.fsf_-_@gnus.org> <83o8a2dbjo.fsf@gnu.org> <86bl62s8qm.fsf@gmail.com> <83czqhdfhm.fsf@gnu.org> <861r6xoxqa.fsf@gmail.com> <83sfzcbmfm.fsf@gnu.org> <86mtpksa0l.fsf@gmail.com> <83a6lkbe02.fsf@gnu.org> <86sfzcjnfr.fsf@gmail.com> <835yw8b6s3.fsf@gnu.org> <86fsvcz0pr.fsf@gmail.com> <834kbsb3uu.fsf@gnu.org> <86a6lkywj0.fsf@gmail.com> <831r6waxz6.fsf@gnu.org> <86h7framo5.fsf@gmail.com> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Andy Moreton > Date: Sat, 14 Aug 2021 19:47:22 +0100 > > On Sat 14 Aug 2021, Eli Zaretskii wrote: > > > Thanks, I've decided to go with a hybrid approach that doesn't change > > how 32-bit builds behaved up to now. > > That looks fine, and the bug reported by the OP now appears fixed in > testing on 32bit and 64bit builds. Thanks for testing.