Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113932 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12120 invoked from network); 2 Apr 2021 22:14:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Apr 2021 22:14:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B34F3180537 for ; Fri, 2 Apr 2021 15:12:44 -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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 2 Apr 2021 15:12:44 -0700 (PDT) Received: by mail-il1-f170.google.com with SMTP id w2so2743036ilj.12 for ; Fri, 02 Apr 2021 15:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FdkYrqKKcSRZqf+JSPetQtXv5IX2McAy5rkKOf3WYy8=; b=NNKtot9VSyxbaiwnBl/d7RTzUlmvTxQg2nbicKn0ZjQiMxa8xNw+3T7WacNu56r0C/ FfxOq2REuU//iM3JfT0gv7YoXVlTybzqr1FVvZLrJfQY5mtHu0F4J9S7AcI+rG5XxO8y NuxXsKWR6ntBCyMAan0QnIqB3Brtwc5dQ7yy1cDjCni3lJwpVLLmWRIQGO2bLD4764QD PUOUuoQO+DMVP4yVhj/r6dniPDjs3f3JZyMG6NsPL2v3X+I8t96T8387suaimY95lx2T +CRLXtNntQu9gzz1TSTaY53IUGQct4BTVot0XDzumbfywCr5pY6HgG1HS6TVGn5dBF+P IFRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FdkYrqKKcSRZqf+JSPetQtXv5IX2McAy5rkKOf3WYy8=; b=ZUep3OTvrD3/MaMCnutmrKjSkAENwoQX4X9mpr5JtZREEos4KN15xW/9TB39zZOHB5 o3rUJHyYN5zTVmK7YxCwPj3IF+TqamUR2VKlhSTpQuRaO74yDTgWPlRkAeZ+KBzlsPSd gqifo5PUecaFmf6W2wyUvnkfYw+m+xrPv1KR/rRG0stUFFssg1YncT0FbF9qr7p693Yd +oK0W7Ykc1PA+iZlmETYdZqKfn6HBxwhZfnVKr2/Bfsc/N861ykemeW1Br51zED1zOrB A102/BmUiZ02GtwXnwFy/M4DteGQJ3oZUkM3qTacgDOKFL42v5fEmFYiW8byVH76bFpd 9hPQ== X-Gm-Message-State: AOAM5319gfQcfWSXtiBf57bD7FF6yj+XIvIsx2p0MRw0ttwb/91JCRRN PK3ZBRCQgKFm3KqxME6W21yYIhpxngxKsCm4GiI= X-Google-Smtp-Source: ABdhPJynODoBvRVax5ZYMtEq3vbZM4lm/+O9kRNwug4xRaJsxUcPKRDgYlC5pwi85TF5ZaFU1bsjHpyi5VxC48Uu8q4= X-Received: by 2002:a92:8752:: with SMTP id d18mr11861253ilm.283.1617401563488; Fri, 02 Apr 2021 15:12:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 3 Apr 2021 00:12:31 +0200 Message-ID: To: Kamil Tekiela Cc: Go Kudo , Levi Morrison , PHP internals Content-Type: multipart/alternative; boundary="000000000000a6a7c305bf04a576" Subject: Re: [PHP-DEV] [VOTE] Object scoped RNG implementation From: ocramius@gmail.com (Marco Pivetta) --000000000000a6a7c305bf04a576 Content-Type: text/plain; charset="UTF-8" On Fri, Apr 2, 2021, 23:56 Kamil Tekiela wrote: > Hi Go Kudo, > > First, let me say that I believe we need such implementation in PHP and I > would like to see object scoped RNG as part of the standard. However, I > have voted no for a number of reasons. Let me list them from the > perspective of a noob PHP user. > > - I really do not understand why we are introducing new functions. Can't > the classes implement the necessary methods to get integers, doubles, and > string of bytes? As a new user I would be completely overwhelmed by all > these functions: rand(), mt_rand(), rng_int(), rng_next(), rng_next64(). > Which one should I use? What is the difference between rng_next() > and rng_next64? > - As soon as I left the RFC page I forgot what the new classes were called. > I still can't tell from memory what's their name. I understand what they > mean, but they are definitely not friendly names. > - What's the difference between MT19937 and XorShift128Plus? They are > different algorithms but which one should I pick? I tested the > implementation locally and I see no difference in performance. > - I am not a fan of adding a new optional parameter to shuffle() and > friends. I'd prefer to have a method in the class that I can pass an array > to. > - What is the default seed? Do I have to provide a seed each time? Why > can't the seed be done automatically? > - Signed? Unsigned? As far as I know, PHP doesn't have unsigned integers. > What's the real-life purpose of this flag? > - I don't see any use in supporting userland implementations. Why can't > they create separate libraries? I don't know about performance, but if > someone wants to have custom RNG then I don't think they worry about > performance. > - When using the functions the performance was 50% worse than when calling > ->next() directly. Is this right or is the implementation going to be > optimized further? The fastest way to get a random number seems to be > mt_rand() based on my tests. > > I would rather like to see a single class called RNG/Random that implements > RNG/RandomInterface. The constructor of the class would take 2 arguments. > The first is the algorithm with a default either MT or XORShift. The second > is an optional seed. If no seed is provided then the seed is generated > automatically like in mt_srand(). The class would then implement methods > like: nextInt(), nextDouble(), nextBytes(), arrayShuffle(), > stringShuffle(), randomArrayKeys(). I would keep the standard functions as > they are. Let them use MT by default. We could even deprecate them in > future if this takes off. > > This would make it painfully obvious what the class does and how to use it. > No more procedural code. I would also make the class final so that you > can't inherit from it, but that is highly opinion-based. > Now that I have written this, I read previous conversations and it looks to > me like what I would like is what you had previously. > > I'm sorry if I complain too much, but I would like to see something like > this implemented, just not like you are proposing right now. It is too > messy for me and I know I wouldn't like it if I had to use it. > Changed my vote to "no" after this in-detail review. Overall, I was conflicted, and voted "yes" especially because we do really need a better and reproducible seeding solution for RNG, and the current API is insufficient. The API proposed so far is quite terrible though, and if the vote passed, we'd have to stick with it for an infinity of years. > --000000000000a6a7c305bf04a576--