Performance#

Recommendation#

The recommended generator for general use is PCG64 or its upgraded variant PCG64DXSM for heavily-parallel use cases. They are statistically high quality, full-featured, and fast on most platforms, but somewhat slow when compiled for 32-bit processes. See Upgrading PCG64 with PCG64DXSM for details on when heavy parallelism would indicate using PCG64DXSM.

Philox is fairly slow, but its statistical properties have very high quality, and it is easy to get an 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 RandomState for reproducing old results. That said, it has a very long history as a default in many systems.

Timings#

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 faster generators.

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 transform rather than the Ziggurat method. 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 uses the same 32-bit generator as RandomState but produces random variates using Generator.

MT19937

PCG64

PCG64DXSM

Philox

SFC64

RandomState

32-bit Unsigned Ints

3.3

1.9

2.0

3.3

1.8

3.1

64-bit Unsigned Ints

5.6

3.2

2.9

4.9

2.5

5.5

Uniforms

5.9

3.1

2.9

5.0

2.6

6.0

Normals

13.9

10.8

10.5

12.0

8.3

56.8

Exponentials

9.1

6.0

5.8

8.1

5.4

63.9

Gammas

37.2

30.8

28.9

34.0

27.5

77.0

Binomials

21.3

17.4

17.6

19.3

15.6

21.4

Laplaces

73.2

72.3

76.1

73.0

72.3

82.5

Poissons

111.7

103.4

100.5

109.4

90.7

115.2

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.

MT19937

PCG64

PCG64DXSM

Philox

SFC64

32-bit Unsigned Ints

96

162

160

96

175

64-bit Unsigned Ints

97