Fast random number generation in Python
C Shell Python
Switch branches/tags
Nothing to show
Latest commit 94c74e3 Dec 13, 2017 @lemire lemire adding blog post ref
Permalink
Failed to load latest commit information.
.gitignore Initial commit Feb 19, 2016
LICENSE Initial commit Feb 19, 2016
README.md adding blog post ref Dec 12, 2017
fastrandmodule.c Adding python3 support. May 17, 2017
runtests.sh Merge branch 'master' of github.com:lemire/fastrand Mar 21, 2016
setup.py Saving... Feb 19, 2016

README.md

fastrand

Fast random number generation in Python

Blog post: Ranged random-number generation is slow in Python…

Requirements: Linux-like system (including a Mac), a C compiler, Python.

python setup.py build
python setup.py install --home=$HOME
PYTHONPATH=$PYTHONPATH:~/lib/python

It is nearly an order of magnitude faster than the alternatives:

python -m timeit -s 'import fastrand' 'fastrand.pcg32bounded(1001)'
10000000 loops, best of 3: 0.0914 usec per loop
python -m timeit -s 'import random' 'random.randint(0,1000)'
1000000 loops, best of 3: 0.698 usec per loop
python -m timeit -s 'import numpy' 'numpy.random.randint(0, 1000)'
1000000 loops, best of 3: 0.795 usec per loop

future work

Also look at https://github.com/rkern/line_profiler