Created
January 12, 2015 10:50
-
-
Save gpr/5f08a40d7bb3bd80ba78 to your computer and use it in GitHub Desktop.
Generate random bytes with Ruby
This file contains 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
# Nothing to require | |
# You can define your seed or generate one using system random function | |
seed = srand | |
prng = Random.new(seed) | |
# Generate X bytes | |
X = 16 | |
bin_str = prng.bytes(X) | |
# Get the hexadecimal string | |
hex_str = bin_str.unpack('H*')[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment