Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34919

Re: Will Math.random return 0.0?

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Will Math.random return 0.0?
Date Sat, 16 Jul 2016 14:19:05 -0400
Organization A noiseless patient Spider
Lines 40
Message-ID <nmdtr1$f2f$1@dont-email.me> (permalink)
References <rand-20160716162126@ram.dialup.fu-berlin.de> <nmdoj7$o5v$1@news2.informatik.uni-stuttgart.de> <nmdtk7$19to$1@gioia.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
Injection-Date Sat, 16 Jul 2016 18:19:13 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="15439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19G1AzrX244Jf0STiig8l4H"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <nmdtk7$19to$1@gioia.aioe.org>
Cancel-Lock sha1:Rfgi/b6t+YDyI6XpixRr20WOZoc=
Xref csiph.com comp.lang.java.programmer:34919

Show key headers only | View raw


On 7/16/2016 2:15 PM, Arne Vajhøj wrote:
> 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.

     Third, no law requires that *all* the state bits become part
of the output.  (Indeed, for java.util.Random *no more than* 32 of
the 48 bits of state contribute to the output of next(), and in the
particular case of nextDouble() only 53 high-order bits from two
consecutive 48-bit states participate.)

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: Will Math.random return 0.0? Thomas Richter <thor@math.tu-berlin.de> - 2016-07-16 18:49 +0200
  Re: Will Math.random return 0.0? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-16 14:15 -0400
    Re: Will Math.random return 0.0? Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-16 14:19 -0400

csiph-web