Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118004 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70234 invoked from network); 20 Jun 2022 03:32:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Jun 2022 03:32:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 69DF31804F8 for ; Sun, 19 Jun 2022 22:21:11 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 19 Jun 2022 22:21:10 -0700 (PDT) Received: by mail-yb1-f179.google.com with SMTP id n144so12989313ybf.12 for ; Sun, 19 Jun 2022 22:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colopl.co.jp; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=XGBmvGkQ5wKCVaCH009Q2CUlZwiFHhvrfenBj0x3Gao=; b=TuDvdel46SF7BQoo6hmGeb1gciwHHTw0uteTgsUg3ffeVt2rLPwXVPXXSCeTGiLL2r /zN7xM8XerI0TXpClrPtHKSK4axYfuqSa9rV4kBz37v+roIVPsBWwNWLDrany/l7WMAy PwnZDySFBH6yEI+jr+G3HxxbFf/H+FKglqdzmu+1bp7chQUH9516gnBQuGaVp653XDrr jDcltRqR7rZP78fItIURYPGFn6OzvwEmzcV2bFGlBDwliVH/LF0DZb1I21bpRCyX1rBL wTEnl8HsLGbC+GRfnibt1/WtEv+PndTOC9h15OCy9vEsrs+FrjEZmE4qDPK2rASCYAj0 /TNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=XGBmvGkQ5wKCVaCH009Q2CUlZwiFHhvrfenBj0x3Gao=; b=oFHBXuNjvFpDbmrRUGfZkWzdK9EWrrCeOEdPCaylQeR0N6rYcK/OJxfx8me0YhmYHb VB33uMMwzBmHimNf45vZ4H5CnHsCmpvFhJdZfia8ujy1NteplRV/38JHmAAXhrlL16hp 1ySv9gC/BsMztrQ7aqVfSvp411HcppJ82Ft5jEKZB2/0O0LMNr1JLgLa1N/OLUa6sb8q /re+V8oTQwQgQ/IXFV1XlHFwhAF8tnC34OxBpf2Npep2ZoiMCIuWiM/4dGTArfiy7GRk 4MMJFPHnzZnBglT/bZvxXSpU6slQma5SC6jDiAyjJvNL8gePaGQpe+BPnJa9Xq7iwwOM KYlA== X-Gm-Message-State: AJIora8NEtIUcQTeUuQZbWeS1q0IyIpxXEFO8svl8/YyEKTNyrjW+jXW /aHm7iE61LWOkKoiDWfbjfl/+HnyYCdljc4g9sBLPaLJtoeXIAg= X-Google-Smtp-Source: AGRyM1vPNRM1H3m/dVTrThW1GpIFaakP3UGQSUe2EyyfrRrSeycbQnOhdmEvwXnb5F6tnYljfu0NIeGwc8ixtkMOdic= X-Received: by 2002:a25:9cc1:0:b0:663:ec65:7fab with SMTP id z1-20020a259cc1000000b00663ec657fabmr23010155ybo.461.1655702470017; Sun, 19 Jun 2022 22:21:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 20 Jun 2022 14:20:59 +0900 Message-ID: To: Marc , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000945edf05e1da45ad" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Random Extension Improvement From: g-kudo@colopl.co.jp (Go Kudo) --000000000000945edf05e1da45ad Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2022=E5=B9=B46=E6=9C=8819=E6=97=A5(=E6=97=A5) 16:25 Marc = : > Hi Go Kudo, > > About "pickArrayKey" I don't like the behavior change on number of array > keys to return either a single key or an array of keys. > It would be better to have different methods for both cases. > > Also it does not describe the behavior if you are requesting more element= s > as in the given array. > > Will the returned list of keys be unique? > > Additionally in array_rand documentation: > > > If multiple keys are returned, they will be returned in the order they > were present in the original array. > > Does that make sense? And would your method behave the same? > > > Am 17.06.2022 21:41 schrieb Go Kudo : > > Hi internals. > > An RFC has been created to fix an issue in Random Extension 5.x. > > https://wiki.php.net/rfc/random_extension_improvement > > Voting on this RFC will begin in two weeks (2022-07-02), in time for the > PHP 8.2 Feature Freeze. (Vote finished in 2022-07-16, Feature Freeze is > 2022-07-19) > > In the unlikely event that the Random Extension 5.x RFC is rejected, this > RFC will become invalid regardless of the outcome of the vote. > > Best regards > Go Kudo > > > Hi Marc. > It would be better to have different methods for both cases. I agree. The current specification is intended to be a drop-in replacement for `array_rand()`. A better API should be provided. In my opinion, the ability to return a single key by value when `int $num` is 1 is unnecessary. I don't need the ability to return a single key by value if `int $num` is 1, since I can simply refer to the first element of the array even if it is returned as an array. What about a signature like `Randomizer::pickArrayKeys(array $array, int $num): array`? The previous behavior when `int $num` is 1 can be easily reproduced as follows: ```php $randomizer =3D new Random\Randomizer(new Random\Engine\Mt19937(1234, MT_RAND_PHP)); [$key] =3D $randomizer->pickArrayKeys(['foo', 'bar', 'baz'], 1); ```php > If multiple keys are returned, they will be returned in the order they were present in the original array. Perhaps there is no particular significance to this specification. I don't think it is necessary, but considering the drop-in replacement from array_rand(), I think it is desirable to leave it as is. At least as of PHP 8.2, we would like to avoid BC Break as much as possible= . Best regards Go Kudo --000000000000945edf05e1da45ad--