From pgilbert902 at gmail.com  Sun Nov  5 21:16:00 2017
From: pgilbert902 at gmail.com (Paul Gilbert)
Date: Sun, 5 Nov 2017 15:16:00 -0500
Subject: [Rd] Extreme bunching of random values from runif with
 Mersenne-Twister seed
In-Reply-To: <855A97DA-B2C5-4132-86AC-2553F8A24AA3@gmail.com>
References: <CA+S-T79BhosJQR7nQkO_Eg3pu7Kvz-0xmUOvsBR5Msa+7W+jow@mail.gmail.com>
 <CAF8bMca0D1ZVsFB40-Pqx3vquuMzUDdaETyRy9oWUm4OCrMyrg@mail.gmail.com>
 <CA+S-T7_DsigtAsj=LBxwoUWNn-2x+R_oDbvGnkDFFTgtnkcRcg@mail.gmail.com>
 <CAF8bMcb-=ijBuXmFpRC+r=ogE+y0rG3MwMvk1kM=mnYgdiWNmg@mail.gmail.com>
 <CA+S-T7_--bJ_xWh+th1KLLf3=JuzS+E6tpiJCMVe=fCGUUNYvg@mail.gmail.com>
 <cd5359ff-ecaf-b998-ef1c-b89d564b9769@gmail.com>
 <3d1b6158-d6a6-fdf1-6498-d3b0655b0113@gmail.com>
 <855A97DA-B2C5-4132-86AC-2553F8A24AA3@gmail.com>
Message-ID: <815e526a-3a93-0f5e-6585-21f81b03b3d9@gmail.com>

I'll point out that there is there is a large literature on generating 
pseudo random numbers for parallel processes, and it is not as easy as 
one (at least me) would intuitively think. By a contra-positive like 
thinking one might guess that it will not be easy to pick seeds in a way 
that will produce independent sequences.

(I'm a bit confused about the objective but) If the objective is to 
produce independent sequence from some different seeds then the RNGs for 
parallel processing might be a good place to start. (And, BTW, if you 
want to reproduce parallel generated random numbers you need to keep 
track of both the starting seed and the number of nodes.)

Paul Gilbert

On 11/05/2017 10:58 AM, peter dalgaard wrote:
> 
>> On 5 Nov 2017, at 15:17 , Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>>
>> On 04/11/2017 10:20 PM, Daniel Nordlund wrote:
>>> Tirthankar,
>>> "random number generators" do not produce random numbers.  Any given
>>> generator produces a fixed sequence of numbers that appear to meet
>>> various tests of randomness.  By picking a seed you enter that sequence
>>> in a particular place and subsequent numbers in the sequence appear to
>>> be unrelated.  There are no guarantees that if YOU pick a SET of seeds
>>> they won't produce a set of values that are of a similar magnitude.
>>> You can likely solve your problem by following Radford Neal's advice of
>>> not using the the first number from each seed.  However, you don't need
>>> to use anything more than the second number.  So, you can modify your
>>> function as follows:
>>> function(x) {
>>>         set.seed(x, kind = "default")
>>>         y = runif(2, 17, 26)
>>>         return(y[2])
>>>       }
>>> Hope this is helpful,
>>
>> That's assuming that the chosen seeds are unrelated to the function output, which seems unlikely on the face of it.  You can certainly choose a set of seeds that give high values on the second draw just as easily as you can choose seeds that give high draws on the first draw.
>>
>> The interesting thing about this problem is that Tirthankar doesn't believe that the seed selection process is aware of the function output.  I would say that it must be, and he should be investigating how that happens if he is worried about the output, he shouldn't be worrying about R's RNG.
>>
> 
> Hmm, no. The basic issue is that RNGs are constructed so that with x_{n+1} = f(x_n),
> x_1, x_2, x_3,... will look random, not so that f(s_1), f(s_2), f(s_3), ... will look random for any s_1, s_2, ... . This is true, even if seeds s_1, s_2, ... are not chosen so as to mess with the RNG. In the present case, it seems that the seeds around 86e6 tend to give similar output. On the other hand, it is not _just_ the similarity in magnitude that does it, try e.g.
> 
> s <- as.integer(runif(1000000, 86.54e6, 86.98e6))
> r <- sapply(s, function(s){set.seed(s); runif(1,17,26)})
> plot(s,r, pch=".")
> 
> and no obvious pattern emerges. My best guess is that the seeds are not only of similar magnitude, but also have other bit-pattern similarities.
> 
> (Isn't there a Knuth quote to the effect that "Every random number generator will fail in at least one application"?)
> 
> One remaining issue is whether it is really true that the same seeds givee different output on different platforms. That shouldn't happen, I believe.
> 
> 
>> Duncan Murdoch
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Extreme bunching of random values from runif with Mersenne-Twister seed
Paul Gilbert