integer type conversion problem/question
Faheem Mitha
faheem at email.unc.edu
Sat Oct 9 16:30:17 EDT 2004
On Sat, 9 Oct 2004, Josiah Carlson wrote:
>> It looks like using a random number generator which uses unsigned ints
>> as its seeds with Python is probably close to impossible then. Can
>> anyone suggest a good C/C++ random number implementation which can be
>> used easily with Python in this fashion? I want something that is
>> full-featured, ie. has reasonable support for different random number
>> distributions. Also, something that was already packaged in a
>> reasonable fashion as part of a shared library would be nice. I
>> suppose something whose seeds are stored as ints or longs would work
>> Ok.
>
> Mersenne Twister is included with Python 2.3 and later (maybe even 2.2,
> I can't remember that far back).
>
> You can use it via:
> import random
>
> It includes various distributions, read the documentation.
I'd looked at this earlier, but they didn't seem to have implemented a C
API. If there is one, I haven't been able to find it in
http://python.org/doc/2.3.4/api/api.html or anywhere else. I don't want to
import Python code into C/C++ even if that is possible. I think it is
easiest to work with a straight C/C++ library and interface it with
Python, assuming that I don't run into type conversion issues.
A random number C module does exist in Python 2.3. On my system (Debian
Sarge) it is /usr/lib/python2.3/lib-dynload/_random.so. However, it is
probably not set up to be directly accessed from C/C++ code.
Faheem.
More information about the Python-list
mailing list