The recommended generator for general use is
PCG64. It is
statistically high quality, full-featured, and fast on most platforms, but
somewhat slow when compiled for 32-bit processes.
Philox is fairly slow, but its statistical properties have
very high quality, and it is easy to get assuredly-independent stream by using
unique keys. If that is the style you wish to use for parallel streams, or you
are porting from another system that uses that style, then
Philox is your choice.
SFC64 is statistically high quality and very fast. However, it
lacks jumpability. If you are not using that capability and want lots of speed,
even on 32-bit processes, this is your choice.
MT19937 fails some statistical tests and is not especially
fast compared to modern PRNGs. For these reasons, we mostly do not recommend
using it on its own, only through the legacy
reproducing old results. That said, it has a very long history as a default in
The timings below are the time in ns to produce 1 random value from a
specific distribution. The original
MT19937 generator is
much slower since it requires 2 32-bit values to equal the output of the
Integer performance has a similar ordering.
The pattern is similar for other, more complex generators. The normal
performance of the legacy
RandomState generator is much
lower than the other since it uses the Box-Muller transformation rather
than the Ziggurat generator. The performance gap for Exponentials is also
large due to the cost of computing the log function to invert the CDF.
The column labeled MT19973 is used the same 32-bit generator as
RandomState but produces random values using
|32-bit Unsigned Ints||3.2||2.7||4.9||2.7||3.2|
|64-bit Unsigned Ints||5.6||3.7||6.3||2.9||5.7|
The next table presents the performance in percentage relative to values generated by the legacy generator, RandomState(MT19937()). The overall performance was computed using a geometric mean.
|32-bit Unsigned Ints||101||121||67||121|
|64-bit Unsigned Ints||102||156||91||199|
All timings were taken using Linux on a i5-3570 processor.
Performance on different Operating Systems¶
Performance differs across platforms due to compiler and hardware availability (e.g., register width) differences. The default bit generator has been chosen to perform well on 64-bit platforms. Performance on 32-bit operating systems is very different.
The values reported are normalized relative to the speed of MT19937 in each table. A value of 100 indicates that the performance matches the MT19937. Higher values indicate improved performance. These values cannot be compared across tables.
|32-bit Unsigned Int||100||119.8||67.7||120.2|
|64-bit Unsigned Int||100||152.9||90.8||213.3|
The relative performance on 64-bit Linux and 64-bit Windows is broadly similar.
|32-bit Unsigned Int||100||129.1||35.0||135.0|
|64-bit Unsigned Int||100||146.9||35.7||176.5|
The performance of 64-bit generators on 32-bit Windows is much lower than on 64-bit operating systems due to register width. MT19937, the generator that has been in NumPy since 2005, operates on 32-bit integers.
|32-bit Unsigned Int||100||30.5||21.1||77.9|
|64-bit Unsigned Int||100||26.3||19.2||97.0|
Linux timings used Ubuntu 18.04 and GCC 7.4. Windows timings were made on Windows 10 using Microsoft C/C++ Optimizing Compiler Version 19 (Visual Studio 2015). All timings were produced on a i5-3570 processor.