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="Robert Klemme" data-source="post: 4644968"><p>My pseudo randomness math is a bit rusty these days but it may be that</p><p>you do not increase randomness by using your approach as you still use</p><p>only one source of randomness. If this is the case, the same can be</p><p>achieved by doing</p><p></p><p>def bytes(n = 16)</p><p>b = ""</p><p>n.times { b << rand(256) }</p><p>b</p><p>end</p><p></p><p>or with 1.9</p><p></p><p>def bytes(n = 16)</p><p>"".tap do |b|</p><p>n.times { b << rand(256) }</p><p>end</p><p>end</p><p></p><p>Kind regards</p><p></p><p>robert</p></blockquote><p></p>
[QUOTE="Robert Klemme, post: 4644968"] My pseudo randomness math is a bit rusty these days but it may be that you do not increase randomness by using your approach as you still use only one source of randomness. If this is the case, the same can be achieved by doing def bytes(n = 16) b = "" n.times { b << rand(256) } b end or with 1.9 def bytes(n = 16) "".tap do |b| n.times { b << rand(256) } end end Kind regards robert [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
Pseudo random
Top