Jan'uary » 日志 » rand() in PHP and Ruby
rand() in PHP and Ruby
Jan 发表于 2008-05-21 14:43:16
See the original post I read here: http://www.boallen.com/random-numbers.html
And the discussion here: http://reddit.com/r/programming/info/6k4gz/comments
It's interesting that PHP on windows has such a fake random function - yeah, I know, no body is true random, but this one is too far away... Guys on reddit says rand() use OS provide rand function buy mt_rand() use PHP's own implementation. It's really a big securiy hole.
And just for fun I write the data visualization code for ruby rand(): (Use RMagick)
You can see the output:

And here's the output from PHP:
And the discussion here: http://reddit.com/r/programming/info/6k4gz/comments
It's interesting that PHP on windows has such a fake random function - yeah, I know, no body is true random, but this one is too far away... Guys on reddit says rand() use OS provide rand function buy mt_rand() use PHP's own implementation. It's really a big securiy hole.
And just for fun I write the data visualization code for ruby rand(): (Use RMagick)
require 'rubygems'
require 'RMagick'
include Magick
SIZE=512
img = Image.new SIZE, SIZE
d = Draw.new
d.fill 'black'
1.upto(SIZE) do |x|
1.upto(SIZE) do |y|
d.point(x, y) if rand > 0.5
end
end
d.draw img
img.write 'random.png'
exit
You can see the output:

And here's the output from PHP:
曾经的这一天...
- » 2007年: LineBuzz
相关日志:
收藏:
QQ书签
del.icio.us
订阅:
Google
抓虾
