added multithreading for random