[Python-checkins] python/nondist/sandbox/twister _random.c,1.2,1.3
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Wed, 25 Dec 2002 12:47:21 -0800
Update of /cvsroot/python/python/nondist/sandbox/twister
In directory sc8-pr-cvs1:/tmp/cvs-serv7568
Modified Files:
_random.c
Log Message:
Eight spaces become tabs!
Index: _random.c
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/twister/_random.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** _random.c 25 Dec 2002 20:44:19 -0000 1.2
--- _random.c 25 Dec 2002 20:47:19 -0000 1.3
***************
*** 4,23 ****
/* ------------------------------------------------------------------
The code in this module was based on a download from:
! http://www.math.keio.ac.jp/~matumoto/MT2002/emt19937ar.html
It was modified in 2002 by Raymond Hettinger as follows:
! * the principal computational lines untouched except for tabbing.
! * renamed genrand_res53() to random_random() and wrapped
! in python calling/return code.
! * genrand_int32() and the helper functions, init_genrand()
! and init_by_array(), were declared static, wrapped in
! Python calling/return code. also, their global data
! references were replaced with structure references.
! * unused functions from the original were deleted.
! new, original C python code was added to implement the
Random() interface.
--- 4,23 ----
/* ------------------------------------------------------------------
The code in this module was based on a download from:
! http://www.math.keio.ac.jp/~matumoto/MT2002/emt19937ar.html
It was modified in 2002 by Raymond Hettinger as follows:
! * the principal computational lines untouched except for tabbing.
! * renamed genrand_res53() to random_random() and wrapped
! in python calling/return code.
! * genrand_int32() and the helper functions, init_genrand()
! and init_by_array(), were declared static, wrapped in
! Python calling/return code. also, their global data
! references were replaced with structure references.
! * unused functions from the original were deleted.
! new, original C python code was added to implement the
Random() interface.
***************
*** 38,50 ****
1. Redistributions of source code must retain the above copyright
! notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
! notice, this list of conditions and the following disclaimer in the
! documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
! products derived from this software without specific prior written
! permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
--- 38,50 ----
1. Redistributions of source code must retain the above copyright
! notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
! notice, this list of conditions and the following disclaimer in the
! documentation and/or other materials provided with the distribution.
3. The names of its contributors may not be used to endorse or promote
! products derived from this software without specific prior written
! permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
***************
*** 69,90 ****
#include "Python.h"
! #include <time.h> // for seeding to current time
/* Period parameters -- These are all magic. Don't change. */
#define N 624
#define M 397
! #define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
typedef struct {
! PyObject_HEAD
! unsigned long state[N];
! int index;
} RandomObject;
static PyTypeObject Random_Type;
! #define RandomObject_Check(v) ((v)->ob_type == &Random_Type)
--- 69,90 ----
#include "Python.h"
! #include <time.h> // for seeding to current time
/* Period parameters -- These are all magic. Don't change. */
#define N 624
#define M 397
! #define MATRIX_A 0x9908b0dfUL /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
typedef struct {
! PyObject_HEAD
! unsigned long state[N];
! int index;
} RandomObject;
static PyTypeObject Random_Type;
! #define RandomObject_Check(v) ((v)->ob_type == &Random_Type)
***************
*** 96,121 ****
genrand_int32(RandomObject *self)
{
! unsigned long y;
! static unsigned long mag01[2]={0x0UL, MATRIX_A};
! /* mag01[x] = x * MATRIX_A for x=0,1 */
! unsigned long *mt;
! mt = self->state;
! if (self->index >= N) { /* generate N words at one time */
! int kk;
! for (kk=0;kk<N-M;kk++) {
! y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
! mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
! }
! for (;kk<N-1;kk++) {
! y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
! mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
! }
! y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
! mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
! self->index = 0;
! }
y = mt[self->index++];
--- 96,121 ----
genrand_int32(RandomObject *self)
{
! unsigned long y;
! static unsigned long mag01[2]={0x0UL, MATRIX_A};
! /* mag01[x] = x * MATRIX_A for x=0,1 */
! unsigned long *mt;
! mt = self->state;
! if (self->index >= N) { /* generate N words at one time */
! int kk;
! for (kk=0;kk<N-M;kk++) {
! y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
! mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
! }
! for (;kk<N-1;kk++) {
! y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
! mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
! }
! y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
! mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
! self->index = 0;
! }
y = mt[self->index++];
***************
*** 130,140 ****
random_random(RandomObject *self)
{
! unsigned long y, z;
! double result;
! y = genrand_int32(self);
! z = genrand_int32(self);
! result = ((y>>5)*67108864.0+(z>>6))*(1.0/9007199254740992.0);
! return PyFloat_FromDouble(result);
}
--- 130,140 ----
random_random(RandomObject *self)
{
! unsigned long y, z;
! double result;
! y = genrand_int32(self);
! z = genrand_int32(self);
! result = ((y>>5)*67108864.0+(z>>6))*(1.0/9007199254740992.0);
! return PyFloat_FromDouble(result);
}
***************
*** 143,165 ****
init_genrand(RandomObject *self, unsigned long s)
{
! int mti;
! unsigned long *mt;
! assert(RandomObject_Check(self));
! mt = self->state;
! mt[0]= s & 0xffffffffUL;
! for (mti=1; mti<N; mti++) {
! mt[mti] =
! (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
! /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
! /* In the previous versions, MSBs of the seed affect */
! /* only MSBs of the array mt[]. */
! /* 2002/01/09 modified by Makoto Matsumoto */
! mt[mti] &= 0xffffffffUL;
! /* for >32 bit machines */
! }
! self->index = mti;
! Py_INCREF(Py_None);
! return Py_None;
}
--- 143,165 ----
init_genrand(RandomObject *self, unsigned long s)
{
! int mti;
! unsigned long *mt;
! assert(RandomObject_Check(self));
! mt = self->state;
! mt[0]= s & 0xffffffffUL;
! for (mti=1; mti<N; mti++) {
! mt[mti] =
! (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
! /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
! /* In the previous versions, MSBs of the seed affect */
! /* only MSBs of the array mt[]. */
! /* 2002/01/09 modified by Makoto Matsumoto */
! mt[mti] &= 0xffffffffUL;
! /* for >32 bit machines */
! }
! self->index = mti;
! Py_INCREF(Py_None);
! return Py_None;
}
***************
*** 170,195 ****
init_by_array(RandomObject *self, unsigned long init_key[], unsigned long key_length)
{
! unsigned int i, j, k; /* was signed in the original code. RDH 12/16/2002 */
! unsigned long *mt;
! mt = self->state;
! init_genrand(self, 19650218UL);
! i=1; j=0;
! k = (N>key_length ? N : key_length);
! for (; k; k--) {
! mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
! + init_key[j] + j; /* non linear */
! mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
! i++; j++;
! if (i>=N) { mt[0] = mt[N-1]; i=1; }
! if (j>=key_length) j=0;
! }
! for (k=N-1; k; k--) {
! mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
! - i; /* non linear */
! mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
! i++;
! if (i>=N) { mt[0] = mt[N-1]; i=1; }
! }
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
--- 170,195 ----
init_by_array(RandomObject *self, unsigned long init_key[], unsigned long key_length)
{
! unsigned int i, j, k; /* was signed in the original code. RDH 12/16/2002 */
! unsigned long *mt;
! mt = self->state;
! init_genrand(self, 19650218UL);
! i=1; j=0;
! k = (N>key_length ? N : key_length);
! for (; k; k--) {
! mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
! + init_key[j] + j; /* non linear */
! mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
! i++; j++;
! if (i>=N) { mt[0] = mt[N-1]; i=1; }
! if (j>=key_length) j=0;
! }
! for (k=N-1; k; k--) {
! mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
! - i; /* non linear */
! mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
! i++;
! if (i>=N) { mt[0] = mt[N-1]; i=1; }
! }
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
***************
*** 201,230 ****
random_seed(RandomObject *self, PyObject *args)
{
! time_t now;
! unsigned long *key;
! unsigned long keylength;
! unsigned long seed;
! unsigned int i;
! PyObject *split;
! PyObject *result = NULL;
! PyObject *arg = NULL;
! PyObject *masklower;
! PyObject *thirtytwo;
! PyObject *little = NULL;
! PyObject *newarg;
! int err;
long hash;
! if (!PyArg_ParseTuple(args, "|O:seed", &arg))
! return NULL;
! if (arg == NULL || arg == Py_None) {
! time(&now);
! return init_genrand(self, (unsigned long)now);
! }
! split = PyList_New(0);
! if (split == NULL)
! return NULL;
if (PyInt_Check(arg) || PyLong_Check(arg))
--- 201,230 ----
random_seed(RandomObject *self, PyObject *args)
{
! time_t now;
! unsigned long *key;
! unsigned long keylength;
! unsigned long seed;
! unsigned int i;
! PyObject *split;
! PyObject *result = NULL;
! PyObject *arg = NULL;
! PyObject *masklower;
! PyObject *thirtytwo;
! PyObject *little = NULL;
! PyObject *newarg;
! int err;
long hash;
! if (!PyArg_ParseTuple(args, "|O:seed", &arg))
! return NULL;
! if (arg == NULL || arg == Py_None) {
! time(&now);
! return init_genrand(self, (unsigned long)now);
! }
! split = PyList_New(0);
! if (split == NULL)
! return NULL;
if (PyInt_Check(arg) || PyLong_Check(arg))
***************
*** 241,286 ****
return NULL;
}
! masklower = PyLong_FromUnsignedLong(0xffffffffU);
! thirtytwo = PyInt_FromLong(32L);
! while (PyObject_IsTrue(arg)) {
! little = PyNumber_And(arg, masklower);
! if (little == NULL)
! goto Done;
! assert(PyLong_Check(little));
! err = PyList_Append(split, little);
! if (err == -1)
! goto Done;
little = NULL;
! newarg = PyNumber_Rshift(arg, thirtytwo);
! if (newarg == NULL)
! goto Done;
! Py_DECREF(arg);
! arg = newarg;
! }
! if (PyList_Size(split) == 0)
! PyList_Append(split, PyLong_FromLong(0L));
! keylength = PyList_Size(split);
! key = (unsigned long *) PyMem_MALLOC(keylength * sizeof(unsigned long));
! if (key == NULL)
! goto Done;
! for (i=0; i<keylength ; i++) {
! seed = PyLong_AsUnsignedLong(PyList_GET_ITEM(split, i));
! if (seed == -1 && PyErr_Occurred()) {
! PyMem_FREE(key);
! goto Done;
! }
! key[i] = seed;
! }
! result = init_by_array(self, key, keylength);
! PyMem_FREE(key);
Done:
! Py_XDECREF(masklower);
! Py_XDECREF(thirtytwo);
! Py_XDECREF(little);
! Py_DECREF(arg);
! Py_DECREF(split);
! return result;
}
--- 241,286 ----
return NULL;
}
! masklower = PyLong_FromUnsignedLong(0xffffffffU);
! thirtytwo = PyInt_FromLong(32L);
! while (PyObject_IsTrue(arg)) {
! little = PyNumber_And(arg, masklower);
! if (little == NULL)
! goto Done;
! assert(PyLong_Check(little));
! err = PyList_Append(split, little);
! if (err == -1)
! goto Done;
little = NULL;
! newarg = PyNumber_Rshift(arg, thirtytwo);
! if (newarg == NULL)
! goto Done;
! Py_DECREF(arg);
! arg = newarg;
! }
! if (PyList_Size(split) == 0)
! PyList_Append(split, PyLong_FromLong(0L));
! keylength = PyList_Size(split);
! key = (unsigned long *) PyMem_MALLOC(keylength * sizeof(unsigned long));
! if (key == NULL)
! goto Done;
! for (i=0; i<keylength ; i++) {
! seed = PyLong_AsUnsignedLong(PyList_GET_ITEM(split, i));
! if (seed == -1 && PyErr_Occurred()) {
! PyMem_FREE(key);
! goto Done;
! }
! key[i] = seed;
! }
! result = init_by_array(self, key, keylength);
! PyMem_FREE(key);
Done:
! Py_XDECREF(masklower);
! Py_XDECREF(thirtytwo);
! Py_XDECREF(little);
! Py_DECREF(arg);
! Py_DECREF(split);
! return result;
}
***************
*** 288,313 ****
random_getstate(RandomObject *self)
{
! PyObject *state;
! PyObject *element;
! int i;
! state = PyTuple_New(N+1);
! if (state == NULL)
! return NULL;
! for (i=0; i<N ; i++) {
! element = PyInt_FromLong((long)(self->state[i]));
! if (element == NULL)
! goto Fail;
! PyTuple_SET_ITEM(state, i, element);
! }
! element = PyInt_FromLong((long)(self->index));
! if (element == NULL)
! goto Fail;
! PyTuple_SET_ITEM(state, i, element);
! return state;
Fail:
! Py_DECREF(state);
! return NULL;
}
--- 288,313 ----
random_getstate(RandomObject *self)
{
! PyObject *state;
! PyObject *element;
! int i;
! state = PyTuple_New(N+1);
! if (state == NULL)
! return NULL;
! for (i=0; i<N ; i++) {
! element = PyInt_FromLong((long)(self->state[i]));
! if (element == NULL)
! goto Fail;
! PyTuple_SET_ITEM(state, i, element);
! }
! element = PyInt_FromLong((long)(self->index));
! if (element == NULL)
! goto Fail;
! PyTuple_SET_ITEM(state, i, element);
! return state;
Fail:
! Py_DECREF(state);
! return NULL;
}
***************
*** 315,346 ****
random_setstate(RandomObject *self, PyObject *state)
{
! int i;
! long element;
! if (!PyTuple_Check(state)) {
! PyErr_SetString(PyExc_TypeError,
! "state vector must be a tuple");
! return NULL;
! }
! if (PyTuple_Size(state) != N+1) {
! PyErr_SetString(PyExc_ValueError,
! "state vector is the wrong size");
! return NULL;
! }
! for (i=0; i<N ; i++) {
! element = PyInt_AsLong(PyTuple_GET_ITEM(state, i));
! if (element == -1 && PyErr_Occurred())
! return NULL;
! self->state[i] = (unsigned long)element;
! }
! element = PyInt_AsLong(PyTuple_GET_ITEM(state, i));
! if (element == -1 && PyErr_Occurred())
! return NULL;
! self->index = (int)element;
! Py_INCREF(Py_None);
! return Py_None;
}
--- 315,346 ----
random_setstate(RandomObject *self, PyObject *state)
{
! int i;
! long element;
! if (!PyTuple_Check(state)) {
! PyErr_SetString(PyExc_TypeError,
! "state vector must be a tuple");
! return NULL;
! }
! if (PyTuple_Size(state) != N+1) {
! PyErr_SetString(PyExc_ValueError,
! "state vector is the wrong size");
! return NULL;
! }
! for (i=0; i<N ; i++) {
! element = PyInt_AsLong(PyTuple_GET_ITEM(state, i));
! if (element == -1 && PyErr_Occurred())
! return NULL;
! self->state[i] = (unsigned long)element;
! }
! element = PyInt_AsLong(PyTuple_GET_ITEM(state, i));
! if (element == -1 && PyErr_Occurred())
! return NULL;
! self->index = (int)element;
! Py_INCREF(Py_None);
! return Py_None;
}
***************
*** 350,358 ****
state to create a new state far away from the original.
! The generator uses constant spaced additive feedback, so shuffling the
! state elements ought to produce a state which would not be encountered
! (in the near term) by calls to random(). Shuffling is normally
! implementing by swapping the ith element with another element ranging
! from 0 to i inclusive. That allows the element to have the possibility
of not being moved. Since the goal is to produce a new, different
state, the swap element is ranged from 0 to i-1 inclusive. This assures
--- 350,358 ----
state to create a new state far away from the original.
! The generator uses constant spaced additive feedback, so shuffling the
! state elements ought to produce a state which would not be encountered
! (in the near term) by calls to random(). Shuffling is normally
! implementing by swapping the ith element with another element ranging
! from 0 to i inclusive. That allows the element to have the possibility
of not being moved. Since the goal is to produce a new, different
state, the swap element is ranged from 0 to i-1 inclusive. This assures
***************
*** 365,369 ****
Finally, the self->index value is set to N so that the generator itself
! kicks in on the next call to random(). This assures that all results
have been through the generator and do not just reflect alterations to
the underlying state.
--- 365,369 ----
Finally, the self->index value is set to N so that the generator itself
! kicks in on the next call to random(). This assures that all results
have been through the generator and do not just reflect alterations to
the underlying state.
***************
*** 376,383 ****
PyObject *iobj;
PyObject *remobj;
! unsigned long *mt, tmp;
! assert(RandomObject_Check(self));
! mt = self->state;
for (i=N-1 ; i>1 ; i--) {
--- 376,383 ----
PyObject *iobj;
PyObject *remobj;
! unsigned long *mt, tmp;
! assert(RandomObject_Check(self));
! mt = self->state;
for (i=N-1 ; i>1 ; i--) {
***************
*** 385,389 ****
remobj = PyNumber_Remainder(n, iobj);
Py_DECREF(iobj);
! if (remobj == NULL)
return NULL;
j = PyInt_AsLong(remobj);
--- 385,389 ----
remobj = PyNumber_Remainder(n, iobj);
Py_DECREF(iobj);
! if (remobj == NULL)
return NULL;
j = PyInt_AsLong(remobj);
***************
*** 407,434 ****
random_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! RandomObject *self;
! self = (RandomObject *)type->tp_alloc(type, 0);
! if (self == NULL)
! return NULL;
! if (random_seed(self, args) == NULL) {
! Py_DECREF(self);
! return NULL;
! }
! return (PyObject *)self;
}
static PyMethodDef random_methods[] = {
! {"random", (PyCFunction)random_random, METH_NOARGS,
! PyDoc_STR("random() -> x in the interval [0,1).")},
! {"seed", (PyCFunction)random_seed, METH_VARARGS,
! PyDoc_STR("seed([n]) -> None. Defaults to current time")},
! {"getstate", (PyCFunction)random_getstate, METH_NOARGS,
! PyDoc_STR("getstate() -> tuple containing the current state.")},
! {"setstate", (PyCFunction)random_setstate, METH_O,
! PyDoc_STR("setstate(state) -> None. Restores generator state.")},
! {"jumpahead", (PyCFunction)random_jumpahead, METH_O,
PyDoc_STR("jumpahead(int) -> None. Create a new state from\n\
the existing state and the supplied integer.")},
! {NULL, NULL} /* sentinel */
};
--- 407,434 ----
random_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
! RandomObject *self;
! self = (RandomObject *)type->tp_alloc(type, 0);
! if (self == NULL)
! return NULL;
! if (random_seed(self, args) == NULL) {
! Py_DECREF(self);
! return NULL;
! }
! return (PyObject *)self;
}
static PyMethodDef random_methods[] = {
! {"random", (PyCFunction)random_random, METH_NOARGS,
! PyDoc_STR("random() -> x in the interval [0,1).")},
! {"seed", (PyCFunction)random_seed, METH_VARARGS,
! PyDoc_STR("seed([n]) -> None. Defaults to current time")},
! {"getstate", (PyCFunction)random_getstate, METH_NOARGS,
! PyDoc_STR("getstate() -> tuple containing the current state.")},
! {"setstate", (PyCFunction)random_setstate, METH_O,
! PyDoc_STR("setstate(state) -> None. Restores generator state.")},
! {"jumpahead", (PyCFunction)random_jumpahead, METH_O,
PyDoc_STR("jumpahead(int) -> None. Create a new state from\n\
the existing state and the supplied integer.")},
! {NULL, NULL} /* sentinel */
};
***************
*** 437,482 ****
static PyTypeObject Random_Type = {
! PyObject_HEAD_INIT(NULL)
! 0, /*ob_size*/
! "_random.Random", /*tp_name*/
! sizeof(RandomObject), /*tp_basicsize*/
! 0, /*tp_itemsize*/
! /* methods */
! (destructor)PyObject_Del, /*tp_dealloc*/
! 0, /*tp_print*/
! 0, /*tp_getattr*/
! 0, /*tp_setattr*/
! 0, /*tp_compare*/
! 0, /*tp_repr*/
! 0, /*tp_as_number*/
! 0, /*tp_as_sequence*/
! 0, /*tp_as_mapping*/
! 0, /*tp_hash*/
! 0, /*tp_call*/
! 0, /*tp_str*/
! PyObject_GenericGetAttr, /*tp_getattro*/
! 0, /*tp_setattro*/
! 0, /*tp_as_buffer*/
! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
! random_doc, /*tp_doc*/
! 0, /*tp_traverse*/
! 0, /*tp_clear*/
! 0, /*tp_richcompare*/
! 0, /*tp_weaklistoffset*/
! 0, /*tp_iter*/
! 0, /*tp_iternext*/
! random_methods, /*tp_methods*/
! 0, /*tp_members*/
! 0, /*tp_getset*/
! 0, /*tp_base*/
! 0, /*tp_dict*/
! 0, /*tp_descr_get*/
! 0, /*tp_descr_set*/
! 0, /*tp_dictoffset*/
! 0, /*tp_init*/
! PyType_GenericAlloc, /*tp_alloc*/
! random_new, /*tp_new*/
! 0, /*tp_free*/
! 0, /*tp_is_gc*/
};
--- 437,482 ----
static PyTypeObject Random_Type = {
! PyObject_HEAD_INIT(NULL)
! 0, /*ob_size*/
! "_random.Random", /*tp_name*/
! sizeof(RandomObject), /*tp_basicsize*/
! 0, /*tp_itemsize*/
! /* methods */
! (destructor)PyObject_Del, /*tp_dealloc*/
! 0, /*tp_print*/
! 0, /*tp_getattr*/
! 0, /*tp_setattr*/
! 0, /*tp_compare*/
! 0, /*tp_repr*/
! 0, /*tp_as_number*/
! 0, /*tp_as_sequence*/
! 0, /*tp_as_mapping*/
! 0, /*tp_hash*/
! 0, /*tp_call*/
! 0, /*tp_str*/
! PyObject_GenericGetAttr, /*tp_getattro*/
! 0, /*tp_setattro*/
! 0, /*tp_as_buffer*/
! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
! random_doc, /*tp_doc*/
! 0, /*tp_traverse*/
! 0, /*tp_clear*/
! 0, /*tp_richcompare*/
! 0, /*tp_weaklistoffset*/
! 0, /*tp_iter*/
! 0, /*tp_iternext*/
! random_methods, /*tp_methods*/
! 0, /*tp_members*/
! 0, /*tp_getset*/
! 0, /*tp_base*/
! 0, /*tp_dict*/
! 0, /*tp_descr_get*/
! 0, /*tp_descr_set*/
! 0, /*tp_dictoffset*/
! 0, /*tp_init*/
! PyType_GenericAlloc, /*tp_alloc*/
! random_new, /*tp_new*/
! 0, /*tp_free*/
! 0, /*tp_is_gc*/
};
***************
*** 485,489 ****
static PyMethodDef module_functions[] = {
! {NULL, NULL} /* sentinel */
};
--- 485,489 ----
static PyMethodDef module_functions[] = {
! {NULL, NULL} /* sentinel */
};
***************
*** 491,499 ****
init_random(void)
{
! PyObject *m;
! Random_Type.ob_type = &PyType_Type;
! m = Py_InitModule3("_random", module_functions, module_doc);
! PyModule_AddObject(m, "Random", (PyObject *)&Random_Type);
}
--- 491,499 ----
init_random(void)
{
! PyObject *m;
! Random_Type.ob_type = &PyType_Type;
! m = Py_InitModule3("_random", module_functions, module_doc);
! PyModule_AddObject(m, "Random", (PyObject *)&Random_Type);
}