fixed a threading issue for random number generation