In addition, moved the rng out. This will allow allocating one instance per worker, rather than every call.