我试图window.crypto.getRandomValues在nodejs脚本中使用该方法.根据我的理解,window当我在节点中运行这样的简单代码时,没有元素:
var array = new Uint32Array(10);
window.crypto.getRandomValues(array);
Run Code Online (Sandbox Code Playgroud)
这就是我收到此错误的原因:
ReferenceError: window is not defined
Run Code Online (Sandbox Code Playgroud)
如何在我的代码中使用此方法?
谢谢
好的,所以我正在研究如何使用Math.random方法生成随机数.到目前为止,我学会了它从一个"随机"种子开始,并将该种子插入到一些复杂的方程中以创建一个随机数.如果种子总是一样,结果总是一样吗?
我听说Math.random的种子是通过当前时间生成的,这是正确的吗?他们必须使用当前时间一直到mili-seconds或其他东西,因为如果你没有,你会得到相同的结果.
种子究竟是什么?是"10:45"之类的时间,还是"10月11日10:45"或某种组合的时间和日期?
我怎样才能找到种子,所以我可以预测输出?
我希望能够插入这个:
alert(Math.floor((Math.random()*10)+1));
Run Code Online (Sandbox Code Playgroud)
进入我的网址栏,并能够预测结果.那可能吗?