[Numpy-discussion] match RNG numbers with R?

Robert Kern robert.kern at gmail.com
Mon Apr 7 10:26:07 EDT 2014


On Mon, Apr 7, 2014 at 3:16 PM, Daπid <davidmenhur at gmail.com> wrote:
>
> On Apr 7, 2014 3:59 AM, "Yaroslav Halchenko" <lists at onerussian.com> wrote:
>> so I would assume that the devil is indeed in R post-processing and would
>> look
>> into it (if/when get a chance).
>
> The devil here is the pigeon and the holes problem. Mersenne Twister
> generates random integers in a certain range. The output is guaranteed to be
> deterministic, uniform, and reproducible.
>
> But when you want to cast those m possible input in n possible outputs, you
> need to do magic (or maths) to keep the new distribution truly uniform.
> Simply getting random bytes and viewing them as ints will give you low
> quality random numbers.
>
> The algorithm that casts MT output to a random integer is probably what is
> different, and perhaps you could find it documented somewhere.

This is ours:

https://github.com/numpy/numpy/blob/master/numpy/random/mtrand/randomkit.c#L259

-- 
Robert Kern



More information about the NumPy-Discussion mailing list