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


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

Re: Will Math.random return 0.0?

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Will Math.random return 0.0?
Date Sat, 16 Jul 2016 14:17:46 -0400
Organization Aioe.org NNTP Server
Lines 30
Message-ID <nmdtob$19to$2@gioia.aioe.org> (permalink)
References <rand-20160716162126@ram.dialup.fu-berlin.de> <nmdoj4$s2i$1@dont-email.me> <nmdoqg$o6a$1@news2.informatik.uni-stuttgart.de>
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:34918

Show key headers only | View raw


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
>
> with a and b some relatively prime numbers. These are not particularly
> good generators, but often simple to implement and fast - even more so
> if b is (one minus) a power of two.
>
> In such a case, zero is a trivial period of the generator, and for that
> reason, the generator is never initialized by zero. It then can be seen
> that it never reaches zero either (given the ring Z_b has no zero dividers).
>
> Random() on such a core random generator would return the number x_n
> divided by b, and hence the output would never be zero.

The argument does not hold water as it is trivial to subtract one
to get a random number that can be zero.

But anyway the Java random number generator is documented to have
a non-zero add part, so ...

Arne

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


Thread

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

csiph-web