Fix coverity CWE676: get rid of rand() function