# Optimized numpy random number generation on Intel CPU - Python
Data Science for Political and Social Phenomena
Author: Guillaume Redoulès

# Optimized numpy random number generation on Intel CPU

## Python Intel distribution

Make sure you have a python intel distribution. When you startup python you should see somethine like :

    Python 3.6.2 |Intel Corporation| (default, Aug 15 2017, 11:34:02) [MSC v.1900 64 bit (AMD64)]
    Type 'copyright', 'credits' or 'license' for more information
    IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

If not, you can force the installation of the intel optimized python with :

    conda update --all
    conda config --add channels intel
    conda install numpy --channel intel --override-channels

oh and by the way, make sure you a running an Intel CPU ;)

## Comparing numpy.random with numpy.random_intel

Let's now test both the rand function with and without the Intel optimization

    import numpy as np
    from numpy import random, random_intel

    %timeit np.random.rand(10**5)

    1.06 ms ± 91.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

    %timeit np.random_intel.rand(10**5)

    225 µs ± 3.46 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

### Find an error or bug? Have a suggestion?

Everything on this site is avaliable on GitHub. Head on over and submit an issue. You can also message me directly by email.