From 39c59bfbf329794d8fe337bd9dff51600c5cbc3b Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Thu, 14 Jan 2021 17:04:36 +0000 Subject: Pass state as doubles This is what is used in the R interface as well and while not a 100% sane, it does seem to work and preserves backwards compatibility. --- src/_syncrng.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/_syncrng.c b/src/_syncrng.c index 5aaa177..bd1612a 100644 --- a/src/_syncrng.c +++ b/src/_syncrng.c @@ -122,43 +122,49 @@ static PyObject *_syncrng_seed(PyObject *self, PyObject *args) uint32_t seed; uint64_t *state = NULL; - if (!PyArg_ParseTuple(args, "k", &seed)) + PyObject *dblObj; + + if (!PyArg_ParseTuple(args, "O", &dblObj)) return NULL; + seed = (uint32_t) PyLong_AsLong(dblObj); lfsr113_seed(seed, &state); - PyObject *pystate = Py_BuildValue("[k, k, k, k]", - state[0], state[1], state[2], state[3]); + PyObject *pystate = Py_BuildValue("[d, d, d, d, d]", + (double) state[0], + (double) state[1], + (double) state[2], + (double) state[3], + -1.0); free(state); return pystate; } static PyObject *_syncrng_rand(PyObject *self, PyObject *args) { - uint32_t i, value, numints; - uint64_t *localstate; + int i; + uint32_t rand; + uint64_t *localstate = malloc(sizeof(uint64_t) * 4); PyObject *listObj; - PyObject *intObj; + PyObject *dblObj; if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &listObj)) return NULL; - // we're just assuming you would never pass more than 4 values - localstate = malloc(sizeof(uint32_t)*5); - numints = PyList_Size(listObj); - for (i=0; i