制作一个真正的随机数发生器?

frr*_*lod 0 javascript php random jquery random-sample

我正在制作一个需要随机化东西的小型Web应用程序.只是它的一个小例子:向用户返回10和10之间的随机数.

我打算用Javascript和jQuery(计算器本身)来做.

我的问题是:如何使其功能真正随机而不是伪随机?PHP函数可能比Javascript更随机吗?

为了这个问题,让我们说我想要的是X和Y之间的真正随机数.

Ted*_*opp 6

No function that you call will be "truly random". They are all PRNGs; most PRNGs are, in fact, quite good and I'd be surprised if they were inadequate for your application. Also, while a few PRNGs are notorious for their small period (Java's Random comes to mind), every modern language that I know of—including JavaScript, PHP, and (with its crypto packages) Java—have very good PRNGs.

The best way to collect "more random" data is to obtain it from an external random source. One possibility is to ask the user to move the mouse around in a window for a certain period of time, collecting the mouse coordinates at regular intervals. Some military, banking, and other high-security systems use hardware like thermal noise sensors to obtain data that is as close to random as one can hope; however, such hardware support is not going to be available to a web app.

Note that hacks like using the system clock are no better than PRNGs; most PRNGs initialize their seed with a combination of such data.