Dave Reid wrote:

> 
> New submission from Dave Reid <seabass...@gmail.com>:
> 
> A particular combination of seed and jumpahead calls seems to force the MT
> generator into a state where it produces a random variate that is outside
> the range 0-1. Problem looks like it might be in
> _randommodule.c:genrand_int32, which produces a value > 0xffffffff for the
> given state, but I don't understand the generator well enough to debug any
> further.
> 
> The attached test case produces 1.58809998297 as the 2nd variate in Python
> 2.7 and 1.35540900431 as the 23rd variate in Python 2.7.3. The problem
> occurs on both Linux (CentOS 6) and Mac OSX (10.6.8), both 64-bit.

A simple way to reproduce the problem:

>>> import random
>>> r = random.Random()
>>> a, b, c = r.getstate()
>>> r.setstate((a, (0xffffffff,)*len(b), c))
>>> r.jumpahead(1)
>>> r.random()
1.8015423506628903


It looks like in random_jumpahead

        mt[i] += i+1;

needs to be masked

        mt[i] = (mt[i] + i + 1) & 0xffffffffUL;

(random_setstate already does that)

_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to