K
Kless
Is safe to use Kernel#rand to get pseudo-random integers?
Is safe to use Kernel#rand to get pseudo-random integers?
For if this can help to somebody, I use a deck of 52 cards to get a
better randomness. Although it could be used a deck of: number to
return * 2 (or 3)
-----------------------
def bytes(n=nil)
# The range of possible values to each card is 256 (0-255), the
# maximum length to representing an ASCII character.
# By default returns 16 bytes (128 bits), a common value in salts
and IVs.
n ||= 16
# Gets 52 cards with values in range 0-255, and then they are
shuffled.
cards = (1..52).map { rand(256) }.shuffle
# Finally gets 'n' cards from the deck, and it is encoded to ASCII.
(1..n).map { cards[rand(52)] }.pack("C*")
end
-----------------------
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.