update to use cryptographic random if it is available

optimize cryptographic random generator.
Merge pull request #2447 from usagi/dev-urandom-update

update to use cryptographic random if it is available