Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112595 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96610 invoked from network); 22 Dec 2020 16:08:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Dec 2020 16:08:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 090EA180384 for ; Tue, 22 Dec 2020 07:40:59 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12olkn2070.outbound.protection.outlook.com [40.92.23.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 22 Dec 2020 07:40:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vbz2p9plTiQoq6vuxpVVxc/jT9kB0lMr6rpPAVoUoubvjIyWIbC5vATfiI9K+6tcKe52z6EaaqbQe+Sbk4d2gkhxvWcxMYBJ7P4X1P903Z/GDO1P/hG8ElXezr8+GAe5mIEm7TqghXZ87236hrGIupHNyZv7ImBpiPlkgSnTsII7xaYV4A66gCghUbz+aymSR2r8DRXMfmKEBxL/uzoTvJXj+KXoq2YgPf5+wh/UwC8/F4JHT7ySIgSzqekjI9D+KHF1NHUBiHw9hDkEn8RE/GMnehgqm/IbmYK/3bxGzJvE0qXHYZz6dcx9lsIiXPiwluhIQKfIl0FHKKXFo/ecrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0eGYHZoMGquaqwnWOJAyj/nvCBenN6fM7qDihTF/g2k=; b=Xuqtz9ZLSkZDMOGbNt4EQrQWjFhMxiknwYywuHZ1HhUYbhrvUpCUmzzCXwsm86QqoGvcQEbdfMaUKGG4w86N5vUuXC5Ki4sRY3GgVC8zn5HUw3u+zZqfrxHDLEEZy2hgM6WZy8YeEhUyC/QPHtpTHn+V93N5t3cuKGdbsAN7Gd0aECijaCo1kyFMHjGL+qZBJqCYNfuQgyaShac4vo92/FGl04r32T1gFtLg6SUKWZryjDR7+GnLRIgCKzCztzJ6MR/8+sQdMPIthL1Ic7ZI0Ex1vzFZCgXDrDCd+0mFCNhqBMadTp+rVaKgCDIwlM9FUX29bNWtN1DwiM8R0r5YjQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0eGYHZoMGquaqwnWOJAyj/nvCBenN6fM7qDihTF/g2k=; b=IWwfBlA2IUS6Bqghs/uGtvuTEsaNymGBekPELCP9/X3aTPPkMoBq69bx7txjJgMCkhv9wc6oM9qr9m8Hq92zhOIak2pL7mY9aat39fX03vYY6JIYSp2yy08jNiIeDS6qGroQGLM5ZJCrmKqMYcHkmq9GxbShMkaf7Xez4uXAYyzHShOJARiINPnoWtWjQyn1kjQPraoFcEDaPiyyletKIfSot2CfjTU3vcikykTLMTaxk9zJIov/naSMo68rX1fMeomTD9jjrGQ68RSnxdGzrZGEDPBPJqEW/daDwUONrCPX5qH0jdC0VpN7BMxJuxCLjiBhhMNzudCHU/kBu7ac5w== Received: from DM6NAM12FT046.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::40) by DM6NAM12HT025.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::333) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.10; Tue, 22 Dec 2020 15:40:56 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc64::51) by DM6NAM12FT046.mail.protection.outlook.com (2a01:111:e400:fc64::142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3676.10 via Frontend Transport; Tue, 22 Dec 2020 15:40:56 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d%4]) with mapi id 15.20.3676.033; Tue, 22 Dec 2020 15:40:56 +0000 To: zeriyoshi , "internals@lists.php.net" Thread-Topic: [PHP-DEV] Re: Improving PRNG implementation. Thread-Index: AQHW1dDvb5ytFzyWEE+DGO7531p+9qn/ZwS0 Date: Tue, 22 Dec 2020 15:40:56 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:FE3DA1DBEA48A45D1D4793D6B46EA24E21389411DE1E44E8B40CEDD1212395B7;UpperCasedChecksum:18B97D4B107160C14DAB8E4CD46D1D3A7496EAD9F3154BF4D7F447BDC27F2B12;SizeAsReceived:7130;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [Fu6klaO9fWysJc3dVQU4j305CLs9l2cHYlnUSk/cDlS7UH+fXkgpxnLwUg2gOwsn] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 1d346793-1201-4035-e6c1-08d8a68ff926 x-ms-traffictypediagnostic: DM6NAM12HT025: x-ms-exchange-minimumurldomainage: cplusplus.com#7933 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: arK6FmG1a/2VbhLfgVwgwmJ5MF+usz8qrDbq7WBwtQBHVVu9IrBiR9ANIl/EhkvuuRnjxj3bY1NI13b9iFYS9DcOBJovD2JhMcI+ZRBJ0GjnE7th2evEQfaYW7zcVVTOKKBu6vTSc/oclMvIy7HaQ66hAYIATpfg/PiwzKUANFM4zcTJVl7YfuMvaBMp1XqDMaWaaDdFGq2ottjZNqSwWmX0CLBQXRMVnnwcVLgWD7yAo1FuN6CDIWHO5NbQq/v627Lr/mSBPTzJPmsR+rZ8ac5NV6fdsIG7BVX1CG60Kkc= x-ms-exchange-antispam-messagedata: 4H5EXBCas/Xee/D3bQLiXP4cAhYuKeXgnggNstYO5ljLkWoyygCr7lxVKxAHXpBNUjS9OscrMWvNYnaGZL/deQKIfkfujipcg16VQDx0YtGCTgKvEbC+1REl4iS3gYNKvji8aIZeK0FrVQlhuKnlFTnOk4nZv43cUgu3EHIrg8urNHVzJucAWnR2MlOuY3Ozp9NQFHhH4dzlr3Y3wiWbZA== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: DM6NAM12FT046.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 1d346793-1201-4035-e6c1-08d8a68ff926 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Dec 2020 15:40:56.2546 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6NAM12HT025 Subject: Re: [PHP-DEV] Re: Improving PRNG implementation. From: tysonandre775@hotmail.com (tyson andre) Hi=A0Go Kudo,=0A= =0A= **A possible alternative that is widely used in other programming languages= is to limit the interface API to only generating bytes/integers,**=0A= and to provide global functions that would use generic random number genera= tor objects (from internal or user-provided code) in their algorithms.=0A= =0A= This would also make it easier to use those generators in brand new algorit= hms that weren't in the initial RFC.=0A= (or in algorithms written by users in PHP)=0A= =0A= This alternative is similar to Java https://docs.oracle.com/javase/7/docs/a= pi/java/util/Collections.html#shuffle(java.util.List,%20java.util.Random)= =0A= and https://docs.oracle.com/javase/7/docs/api/java/util/Random.html=0A= and C++ https://www.cplusplus.com/reference/algorithm/shuffle/=0A= where the algorithms accept a random number generator conforming to some in= terface=0A= and Python https://docs.python.org/3/library/random.html#random.shuffle=0A= =0A= ```=0A= interface PRNGInterface { =0A= public function random[Signed]Int(): int; // between PHP_INT_MIN and P= HP_INT_MAX (4 bytes or 8 bytes)=0A= public function randomBytes(int $length): string // $length bytes of ra= w data=0A= // possibly randomByte(): int // between 0 and 255=0A= // public function randomIntInRange(int $min, int $max)=0A= // __serialize(), __unserialize() may be provided, but may be counterpr= oductive for classes that wrap /dev/urandom or random_bytes()?=0A= }=0A= // possibly provide a trait that provides defaults based on abstract functi= on randomInt=0A= =0A= function whateverprefixornamespace_rand(PRNGInterface $rng, [int $min, int = $max]): int {}=0A= // If this is intended to be secure, whateverprefix_array_rand may need to = avoid the optimizations used by array_rand for sparse arrays=0A= function whateverprefixornamespace_array_rand(PRNGInterface $rng, array $ar= ray, ...): int {}=0A= function whateverprefixornamespace_shuffle(PRNGInterface $rng, array &$arra= y): bool;=0A= // alternately might be possible by extending existing global functions wit= h an optional parameter=0A= ```=0A= =0A= Thanks,=0A= - Tyson=