Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Will Math.random return 0.0? Date: Sat, 16 Jul 2016 13:11:27 -0400 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 16 Jul 2016 17:11:35 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="1440"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iw/uwMR41EQw6cmUfksl9" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: Cancel-Lock: sha1:yIUK7tWIXu6VLivHppLyAHPwXME= Xref: csiph.com comp.lang.java.programmer:34916 On 7/16/2016 12:53 PM, Thomas Richter wrote: > Am 16.07.2016 um 18:49 schrieb Eric Sosman: > >> >>> Can we be sure that it will ever terminate? >> >> Yes. >> > No. A couple of well-understood "random" generators are simply of the form > > x_n = (x_{n-1} * a) mod b ... and Math.random() is *documented* to use a different generator. The question of whether Math.random() will ever return 0.0 boils down to whether two successive calls to Random#next() will return 27 and 26 (respectively) zero bits from among the 96 bits produced by the *documented* base algorithm. I lack sufficient mathematical prowess to say whether this is possible. ... but I claim, nonetheless, that Stefan's program will terminate: - It may terminate on its own by generating 0.0, or - Whoever is running it will tire of the exercise and stop it, or - The JVM, O/S, hardware, or power will fail. No matter which of these happens, the program will have terminated. -- esosman@comcast-dot-net.invalid "Don't be afraid of work. Make work afraid of you." -- TLM