Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
Pseudo random
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Kless" data-source="post: 4644963"><p>For if this can help to somebody, I use a deck of 52 cards to get a</p><p>better randomness. Although it could be used a deck of: number to</p><p>return * 2 (or 3)</p><p></p><p>-----------------------</p><p>def bytes(n=nil)</p><p># The range of possible values to each card is 256 (0-255), the</p><p># maximum length to representing an ASCII character.</p><p></p><p># By default returns 16 bytes (128 bits), a common value in salts</p><p>and IVs.</p><p>n ||= 16</p><p></p><p># Gets 52 cards with values in range 0-255, and then they are</p><p>shuffled.</p><p>cards = (1..52).map { rand(256) }.shuffle</p><p></p><p># Finally gets 'n' cards from the deck, and it is encoded to ASCII.</p><p>(1..n).map { cards[rand(52)] }.pack("C*")</p><p>end</p></blockquote><p></p>
[QUOTE="Kless, post: 4644963"] 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 [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Pseudo random
Top