Changes to avoid rand() lock contention