Created
August 9, 2011 12:20
-
-
Save rishav/1133897 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> ActiveSupport::SecureRandom.base64(10) | |
=> "Fa8ILYFgMA12LA==" | |
>> ActiveSupport::SecureRandom.hex(6) | |
=> "82c82a15110a" | |
>> ActiveSupport::SecureRandom.random_bytes(16) | |
=> "u[\205\326\2654\301;'\340\372\2539r\035\313" | |
>> ActiveSupport::SecureRandom.random_number(5) | |
=> 0 |
Thanks :). I haven't faced the blocking issue yet, but this defintely helps :). I just did a bit of initial lookup, ActiveSupport::SecureRandom does use /dev/urandom.
You generally don't see the blocking on regular working machines (desktops, busy servers that r/w things all the time, etc.). I've surely had several blockages over with Hadoop when it used SecureRandom generation. As the name goes, its only to be used when you really require that level of randomness (crypto purposes mostly) :)
Anyhow, not sure what ruby's impl may be but if your system entropy pool's dry - its gonna block, that's all I was trying to say :-)
And thanks for letting me know, I probably wouldn't have factored this in until I encountered it somewhere :).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SecureRandom uses /dev/random which'd block until it has enough entropy to provide you some random bytes. Where possible, its good to avoid using this (on machines that are idle, it'd sometimes block the call for ~2 minutes, depending on the hardware). Use general pseudo random generation calls instead (not sure what Ruby has for those, am no Ruby API guy, but it would use /dev/urandom)