From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.7 required=3.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 6E39C1F463 for ; Wed, 25 Sep 2019 11:34:33 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 030CF120B55; Wed, 25 Sep 2019 20:34:24 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 65F09120B3C for ; Wed, 25 Sep 2019 20:34:20 +0900 (JST) Received: by filter0059p3iad2.sendgrid.net with SMTP id filter0059p3iad2-17591-5D8B50BD-83 2019-09-25 11:34:21.766963684 +0000 UTC m=+140746.923692680 Received: from herokuapp.com (unknown [184.73.122.220]) by ismtpd0007p1iad2.sendgrid.net (SG) with ESMTP id j2VU2vYeRFSGI4mr6YHKRQ for ; Wed, 25 Sep 2019 11:34:21.733 +0000 (UTC) Date: Wed, 25 Sep 2019 11:34:21 +0000 (UTC) From: hanmac@gmx.de Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70638 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16180 X-Redmine-Issue-Author: BillyRuffian X-Redmine-Sender: Hanmac X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?z6kUDlxbGclXLcwluHLUb5EO6uh6mW1Jn0ZSGyxj3H3ZkVdxywqRZQhD5MqxAL?= =?us-ascii?Q?WJyUUO+Hqo5K1CzHACrPwU0AALOj3zmaYut+dQ=2F?= =?us-ascii?Q?yeWSWOAD0mlgF0ir30uUhipE6Tnq8BBJ5534mDE?= =?us-ascii?Q?7qupKtgykd2V=2F98zbVecirHIYicNt7KvoVDNhYE?= =?us-ascii?Q?5jlGvXk5SqG8p?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95083 Subject: [ruby-core:95083] [Ruby master Bug#16180] Random.rand(max) ignores / is broken when max ceiling value is a float X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #16180 has been updated by Hanmac (Hans Mackowiak). your cases are documented there: https://ruby-doc.org/core-2.6.4/Kernel.html#method-i-rand `When max.abs is greater than or equal to 1, rand returns a pseudo-random integer greater than or equal to 0 and less than max.to_i.abs.` `Negative or floating point values for max are allowed, but may give surprising results.` ---------------------------------------- Bug #16180: Random.rand(max) ignores / is broken when max ceiling value is a float https://bugs.ruby-lang.org/issues/16180#change-81715 * Author: BillyRuffian (Nigel Brookes-Thomas) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] ruby 2.7.0preview1 (2019-05-31 trunk c55db6aa271df4a689dc8eb0039c929bf6ed43ff) [x86_64-darwin18] Calling `rand` with a float of > 1 always return 0. Calling `rand` with a float 0 < value > 1 will ignore the ceiling value. e.g. ``` rand(1.1) => 0 rand(1.1) => 0 rand(0.5) => 0.9501516156613756 rand(0.5) => 0.6864252478379304 ``` -- https://bugs.ruby-lang.org/