Skip to content

Instantly share code, notes, and snippets.

@lucastheis
Created November 28, 2013 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucastheis/7697118 to your computer and use it in GitHub Desktop.
Save lucastheis/7697118 to your computer and use it in GitHub Desktop.
Demonstrates the problem with matplotlib resetting the random seed.
#!/usr/bin/env python
from distutils.core import setup, Extension
modules = [
Extension('_test',
language='c++',
sources=[
'test.cpp'])]
setup(
name='test',
version='0.0.1',
author='Lucas Theis',
author_email='lucas@theis.io',
ext_modules=modules)
#include <Python.h>
#include <stdlib.h>
#include <iostream>
using std::cout;
using std::endl;
PyObject* test(PyObject*, PyObject*, PyObject*) {
cout << rand() % 100 << endl;
cout << rand() % 100 << endl;
cout << rand() % 100 << endl;
cout << endl;
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef test_methods[] = {
{"test", (PyCFunction)test, METH_NOARGS, 0},
{0}
};
PyMODINIT_FUNC init_test() {
Py_InitModule3("_test", test_methods, 0);
}
from numpy.random import randn
from matplotlib.pyplot import imsave
from _test import test
I = randn(128, 128)
imsave('test.png', I)
test()
imsave('test.png', I)
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment