[問題] 請問這Algorithm

看板C_Sharp作者 (不能閒下來!!)時間14年前 (2011/03/16 13:04), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/2 (看更多)
從一本書中提到的 如果事件的概率存在一個陣列裡,可以用以下方法產生一個隨機事件 Ramdom random = new Random(); int NextEvevt(double[] probabilities) { double p = random.NextDouble(); for ( int i = 0 ; i< probailities.Lebgth -1; i++) { if(p< probabilities[i]) return i; p-=probabilites[i]; } return probabilities[probabilities.Length-1]; } 有點無頭...感覺上是書少寫了啥嗎0.0? -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.86.218.101 ※ 編輯: kingofsdtw 來自: 219.86.218.101 (03/16 13:10) ※ 編輯: kingofsdtw 來自: 219.86.218.101 (03/16 14:14)

03/16 18:27, , 1F
請問是從哪一本書看到的?
03/16 18:27, 1F
文章代碼(AID): #1DW4JYYr (C_Sharp)
文章代碼(AID): #1DW4JYYr (C_Sharp)