make randomPermutation thread safe