获取随机数生成器种子的当前日期时间

发布于 2024-09-15 12:42:19 字数 59 浏览 3 评论 0原文

最好是长的。

我能找到的所有示例都是将日期/时间作为字符串获取,而不是任何标量值。 :)

Preferably as a long.

All the example I can find are getting the date/time as a string and not any scalar value. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

季末如歌 2024-09-22 12:42:19

如果您确实希望当前时间较长,请尝试System.currentTimeMillis()。或者,您可以使用 new Date().getTime()

然而,使用当前时间作为随机数生成器种子是一个非常糟糕的选择(至少,如果您将随机数用于任何重要的事情,例如密码学)。您可能希望考虑使用随机源,例如 /dev/urandom (如果您的平台上可用)。

If you really want the current time as a long, try System.currentTimeMillis(). Alternatively, you can use new Date().getTime().

However, using the current time as a random number generator seed is a very poor choice (at least, if you are using the random numbers for anything important, such as cryptography). You may wish to consider using a random source such as /dev/urandom (if available on your platform).

孤独陪着我 2024-09-22 12:42:19

System.currentTimeMillis 返回一个 long。

http://下载。 oracle.com/javase/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()

还有 System.nanoTime()。

System.currentTimeMillis returns a long.

http://download.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#currentTimeMillis()

there is also System.nanoTime().

弱骨蛰伏 2024-09-22 12:42:19

要生成随机数,您可以使用以下代码:

var randomnumber=new Date().getUTCMilliseconds();
var rand = Math.floor((Math.random() * randomnumber) + 1); 
document.write(rand);

To generate a random number you can use this code:

var randomnumber=new Date().getUTCMilliseconds();
var rand = Math.floor((Math.random() * randomnumber) + 1); 
document.write(rand);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文