fixed unexpected crash due to rand