Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80413 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97561 invoked from network); 12 Jan 2015 09:31:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2015 09:31:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.199 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.199 imap11-2.ox.privateemail.com Received: from [192.64.116.199] ([192.64.116.199:38434] helo=imap11-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/C0-26669-68493B45 for ; Mon, 12 Jan 2015 04:31:50 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 9FA108800E2; Mon, 12 Jan 2015 04:31:47 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap11.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap11.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id uEcdDwPGKkiI; Mon, 12 Jan 2015 04:31:47 -0500 (EST) Received: from [137.50.28.190] (oa-res-28-190.wireless.abdn.ac.uk [137.50.28.190]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 4D4108800D5; Mon, 12 Jan 2015 04:31:44 -0500 (EST) 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> <54B38EA6.8070402@lerdorf.com> Mime-Version: 1.0 (1.0) In-Reply-To: <54B38EA6.8070402@lerdorf.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Message-ID: <47FF88D5-14F8-4844-A9DD-51532FBF3588@ajf.me> Cc: Stanislav Malyshev , Yasuo Ohgaki , PHP Internals List X-Mailer: iPhone Mail (12B440) Date: Mon, 12 Jan 2015 09:31:36 +0000 To: Rasmus Lerdorf Subject: Re: [PHP-DEV] rand(), mt_rand() and limits From: ajf@ajf.me (Andrea Faulds) Hi Rasmus, > On 12 Jan 2015, at 09:06, Rasmus Lerdorf wrote: >=20 > 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. C devs are also familiar with the usage of strtok, but it doesn't make an AP= I with global state any less flawed. The problem with rand() and srand() is they're used for three different purp= oses, only one of which they're terribly fitting for: - To produce a non-repeatable sequence of random numbers (works OK if srand(= ) isn't used) - To produce a repeatable sequence of random numbers (works, but only if you= and the sole user of the global random number generator, which is not guar= anteed by any means) > 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. >=20 > https://www.google.com/search?q=3Dminecraft+seeds No, procedural generation (which I've done) is considerably more sophisticat= ed and is done using a deterministic seeded noise generator. Using random nu= mbers from something like rand() just gets you garbage. -- Andrea Faulds http://ajf.me/=