Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80412 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94932 invoked from network); 12 Jan 2015 09:06:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2015 09:06:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain lerdorf.com designates 209.85.216.179 as permitted sender) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.216.179 mail-qc0-f179.google.com Received: from [209.85.216.179] ([209.85.216.179:39674] helo=mail-qc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D0/60-26669-CAE83B45 for ; Mon, 12 Jan 2015 04:06:52 -0500 Received: by mail-qc0-f179.google.com with SMTP id c9so16897372qcz.10 for ; Mon, 12 Jan 2015 01:06:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type; bh=NUQMGzQq3HyMNDQtcZfX3f9pXkmzCABAUd48wM7xtsM=; b=erXhpOEvsJPVyQvbP3RXOGObnM2SgIfUNjdGHRvXjqWd94zNuen2sOwX/wcp0b2FyW e4D/0UMjiddJzXs2UqbhcEIyOpu1L0Z+5APaQD8FEMoXIgwrVMsfzelpiE2YlwQTT8Pm P0Jzux0+hVSVjehksQUg6Ds+CS43kvfZqdcZjVPU21tUpcvprmeljprbd7nr3kbRE9sZ AUThk89FGgwlf9DXcB6o/OtCRYek2KzLm6XbWnflJ2fv3h+JoWwvWwfE7B20vsB831cK f5i56wgCfOWHgD8oVzlr+b64fmPG6Y8i7QgaC2getOtliCj1QlnUMq/OjRRqRVzTkbs6 MXWA== X-Gm-Message-State: ALoCoQnDbbK3xBiRBRLi3KqDDw2i1jaGkA5BqjjiWmDOH9216WdR4yY5Q3nANimftxsTCjhM1jtE X-Received: by 10.224.43.202 with SMTP id x10mr46553890qae.16.1421053609793; Mon, 12 Jan 2015 01:06:49 -0800 (PST) Received: from [192.168.200.14] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPSA id l10sm4225384qaf.48.2015.01.12.01.06.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Jan 2015 01:06:48 -0800 (PST) Message-ID: <54B38EA6.8070402@lerdorf.com> Date: Mon, 12 Jan 2015 01:06:46 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Stanislav Malyshev , Andrea Faulds CC: Yasuo Ohgaki , PHP Internals List References: <54B30DB9.3000003@seld.be> <76B8D342-43E7-42E6-AD82-FCF7C5CA8658@ajf.me> <54B31D77.9010100@gmail.com> <976B7B2E-7BC9-4514-ABF3-C0DA3ED98897@ajf.me> <54B32145.80501@gmail.com> <54B32BEA.5090507@gmail.com> In-Reply-To: <54B32BEA.5090507@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="e4a4J0MK8rxh8L1tEQVFOwStG3X1Gjl9O" Subject: Re: [PHP-DEV] rand(), mt_rand() and limits From: rasmus@lerdorf.com (Rasmus Lerdorf) --e4a4J0MK8rxh8L1tEQVFOwStG3X1Gjl9O Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 01/11/2015 06:05 PM, Stanislav Malyshev wrote: > Hi! >=20 >> Also, FWIW, anyone who used the Suhosin patch couldn=E2=80=99t use sra= nd() >> because it disabled it. >=20 > And? You can disable any function in PHP, that doesn't mean anything. >=20 >> Because if we don=E2=80=99t break it, people will continue to rely on = it, and >> this binds our hands for future versions. >=20 > Sorry, that doesn't sound even remotely like a good reason. It doesn't > provide any benefit to the user, but produces problems for those who us= e > it. The gain for the users is zero, the added trouble - for those who > use the feature - is substantial. >=20 >> Also, those people will have their code break anyway if they upgrade >> their OS and it changes its random number generator. >=20 > If they used mt_rand that is not true. And OS RNG changes are not that > frequent. E.g. the manual for srand on Mac (and, likely, all BSD) says:= >=20 > The srand() function sets its argument seed as the seed for a new > sequence of pseudo-random numbers to be returned by rand(). > These sequences are repeatable by calling srand() with the same seed va= lue. >=20 > The Linux manual says: >=20 > The srand() function sets its argument as the seed for a new > sequence of pseudo-random integers to be returned by rand(). > These sequences are repeatable by calling srand() with the same seed va= lue. >=20 > I would say the expectation here is pretty clear. Yes, there is plenty of code out there that relies on srand()+rand() returning a repeatable sequence of pseudo-random numbers. I have written some myself. C devs are very familiar with this behaviour of srand. There are tons of uses for this in game-related code. Think of something like Minecraft world seeds. I bet Minecraft even uses this, or at least the Java version of this, for generating its worlds. The worlds are randomly generated, but if you get a particularly cool world you can check the seed and give that seed to a friend and your friend can get the same world generated. There are entire web sites dedicated to sharing cool Minecraft seeds like this. https://www.google.com/search?q=3Dminecraft+seeds -Rasmus --e4a4J0MK8rxh8L1tEQVFOwStG3X1Gjl9O Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAlSzjqYACgkQlxayKTuqOuCzHACfY0WKdNOrOrQRm17XWa2/ThQG TVYAn23ZIoghVGSce4F/OGmAX65skUq1 =j3V9 -----END PGP SIGNATURE----- --e4a4J0MK8rxh8L1tEQVFOwStG3X1Gjl9O--