TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

OpenBSD bug in the random() function

31 点作者 muks大约 13 年前

4 条评论

Yrlec大约 13 年前
While not exactly a bug, but if you run this code in Java:<p><pre><code> for(int i = 0; i&#60; 100; i++){ Random random = new Random(i); System.out.println(random.nextDouble()); }</code></pre> It prints the following sequence (at least on JDK 7 and Win 7):<p><pre><code> 0.730967787376657 0.7308781907032909 0.7311469360199058 0.731057369148862 0.7306094602878371 0.730519863614471 0.7307886238322471 0.7306990420600421 0.7302511331990172 0.7301615514268123 </code></pre> I know that you're not supposed to recreate the Random-instance like that but it's still a bit odd that the initial values in each sequence are so similar to each other.
评论 #3731620 未加载
评论 #3730674 未加载
评论 #3730728 未加载
评论 #3736483 未加载
calloc大约 13 年前
Or why maybe using random() is a terrible idea. Use arc4random() instead on FreeBSD/OpenBSD/Mac OS X for a MUCH better random number generation, and best of all it is auto-seeded.<p>Obligatory XKCD: <a href="http://xkcd.com/221/" rel="nofollow">http://xkcd.com/221/</a>
评论 #3730805 未加载
评论 #3731134 未加载
评论 #3730790 未加载
michaelni大约 13 年前
One issue with the OpenBSD "bug" that i think hasnt been mentioned is that while openbsds srandom(0) leading to a 0 sequence sucks. The fix everyone is using (including up to date OpenBSD trunk) causes srandom(X) and srandom(Y) to produce the same sequence for at least one pair of distinct X and Y. This probably is less an issue but still. For example linux debian with gnu libc produces the same sequence after srandom(0) and srandom(1). Namely 1804289383 846930886 1681692777 1714636915 ...
dfc大约 13 年前
It seems like the right thing to do would be to spend the time composing the email to tech@o.o and then write the blog post.
评论 #3730935 未加载