Use random_*() instead of rand(), for thread safety.