Using lock for random