update to use cryptographic random if it is available

optimize cryptographic random generator.