Performance issue with specifying random number generator


I like the ability to specify the random number generator (RNG) in functions like rand().

This feature would be much more useful if we could tell rand() to use the default RNG, rather than one we supply. This could be achieved either by:

  1. Exposing the name of the default RNG (that is, the one we seed with srand()), or
  2. Making the RNG a keyword argument.

This problem arises because I have some pieces of code that I sometimes want to run with the system RNG and sometimes without. Right now, I can not find an elegant way to do this, and have to either use a branch or duplicate a lot of code.

I originally tried to resolve the problem by having my code create a new RNG when one is not specified. However, this was happening so often that the creation of the MersenneTwister became the dominant cost of the computation.



Distributions.jl using a custom random number generator

For now, Base.Random.GLOBAL_RNG should work to pass as AbstractRNG for the default system RNG. The issue above discusses making it simpler.