存档

文章标签 ‘rand’

PHP的随机和伪随机

2012年2月12日 评论已被关闭

随机和伪随机的可视化视图,区别很明显了,PHP可以通过下面的方法获取真的随机数,但是我感觉方法不是很优雅。

Simple Visual Analysis

One way to examine a random number generator is to create a visualisation of the numbers it produces. Humans are really good at spotting patterns, and visualisation allows you to use your eyes and brain directly for this purpose. While you shouldn’t consider this type of approach an exhaustive or formal analysis, it is a nice and quick way to get a rough impression of a given generator’s performance. The bitmaps shown below are sections of larger bitmaps created by Bo Allen in April 2008 to examine the quality of two random number generators. Bo created the bitmap on the left with RANDOM.ORG’s Bitmap Generator, which is of course a True Random Number Generator (TRNG), and the bitmap on the right with the rand() function from PHP on Microsoft Windows, which is a Pseudo-Random Number Generator (PRNG).

Bitmap generated by RANDOM.ORG Bitmap generated with PHP rand() on Microsoft Windows
RANDOM.ORG PHP rand() on Microsoft Windows

阅读全文…

分类: 技术点滴 标签: ,