Skip to content

Instantly share code, notes, and snippets.

@rishav
Created August 9, 2011 12:20
Show Gist options
  • Save rishav/1133897 to your computer and use it in GitHub Desktop.
Save rishav/1133897 to your computer and use it in GitHub Desktop.
>> 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
@rishav
Copy link
Author

rishav commented Sep 4, 2011

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.

@QwertyManiac
Copy link

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 :-)

@rishav
Copy link
Author

rishav commented Sep 4, 2011

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