view pymt.cpp @ 1:f63d649f91b4 default tip

fix include path
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Mon, 19 May 2008 10:23:11 +0200
parents 0fa810263337
children
line wrap: on
line source

#include "MersenneTwister.h"
#include "Python.h"

static MTRand mt;

static PyObject *
pymt_seed(PyObject *self, PyObject *args) {
	long int seed;
	
	if (!PyArg_ParseTuple(args, "l", &seed))
		return NULL;
	
	mt.seed(seed);
	
	Py_INCREF(Py_None);
	return Py_None;
}

static PyObject *
pymt_randint(PyObject *self, PyObject *args) {
	return PyLong_FromUnsignedLong(mt.randInt());
}

static PyObject *
pymt_random(PyObject *self, PyObject *args) {
	return PyFloat_FromDouble(mt.randExc());
}

static PyMethodDef pymtMethods[] = {
	{"seed",		pymt_seed,		METH_VARARGS, "Set seed."},
	{"randint",		pymt_randint,	METH_VARARGS, "Returns random integer."},
	{"random",	pymt_random,	METH_VARARGS, "Returns random number in the interval [0, 1)."},
	{NULL,				NULL}
};

extern "C" void initpymt() {
	(void) Py_InitModule3("pymt", pymtMethods, "Mersenne Twister");
}

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.