看板 java 關於我們 聯絡資訊
※ 引述《necole236 (necole236)》之銘言: : http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html#Random() : Random : public Random() : Creates a new random number generator. Its seed is initialized to a value : based on the current time: : public Random() { this(System.currentTimeMillis()); } : Two Random objects created within the same millisecond will have the same : sequence of random numbers. : 我看到的定義是這樣子寫的 : 他並沒有說除了當前時間之外,還做了什麼「會設一個和其他 invocation : 很可能會不同的值作 seed」 : 假設你是對的,那他是如何設定一個不同的值做 seed ? 我那段是在 JDK5 的 API 找出來的. 看來 Sun 在 JDK5 改變了 Random no-op constructor . JDK5 裡的 Random(): public Random() { this(++seedUniquifier + System.nanoTime()); } alien -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.155.236.82
necole236:請問 seedUniquifier 的值到底是多少呢? 07/29 17:58
necole236:seedUniquifier = 8682522807148012L; 是從何而來 @_@ 07/29 18:00
adrianshum:不懂你在問什麼, 什麼叫從何而來? 07/29 18:07
necole236:是誰定義 seedUniquifier 就是這個數值的 07/29 18:08
necole236:這是google到的,為什麼這個數字這麼特別? 07/29 18:10
adrianshum:Sun 的 developer 設的. 至於為什麼要取這數就得問他了 07/29 18:11
adrianshum:可是理論上用什麼數值也沒有太大關係吧 07/29 18:13
necole236:當然有關係, google true random 就知道了 07/29 18:25
adrianshum:沒有關係. 重點是取seed的logic,單是那個seedUniquifer 07/29 19:42
adrianshum:的起始值不同,對 true random 與否一點關係都沒有 07/29 19:44
sunneo:電腦上的random都是pseudo random吧? 07/29 22:07
adrianshum:其實是的... 不過有些人還蠻介懷能不能預測seed 吧 07/30 12:06