Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Will Math.random return 0.0? Date: Sat, 16 Jul 2016 14:15:33 -0400 Organization: Aioe.org NNTP Server Lines: 32 Message-ID: References: NNTP-Posting-Host: 7SK6yTFfqwlIPNBLl3l7Qg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:34917 On 7/16/2016 12:49 PM, Thomas Richter wrote: > Am 16.07.2016 um 17:24 schrieb Stefan Ram: >> I wrote the following program. >> >> public final class Main >> { public static void main( final java.lang.String[] args ) >> { while( java.lang.Math.random() != 0.0 ); >> java.lang.System.out.println( "0.0" ); }} >> >> What do you expect it's (average) runtime to be >> on average hardware? >> >> Can we be sure that it will ever terminate? > > No, you cannot. Sure? > If random() is implemented by the average (=bad) linear > congruence generator, then zero will never be the output of random(). Not true. First LCG's can have seed zero and a good cycle as long as the add part is non-zero. Second even for an MLCG (with add part zero) where seed can not be zero, then the random numbers can include zero simply by subtracting one. Arne