Factored out some common code in RNG caching for functions interface (coverage now 98.9%)