Assertion to quiet CID #1223701
Don't call rand().  Closes CID #1233594
Unlock mutex.  Closes CID #1243441
Use size_t instead of int