[問題] random語法怎麼用??

看板C_Sharp (C#)作者 (我想要ALL PASS...)時間19年前 (2006/03/29 22:21), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/4 (看更多)
用random寫出骰子程式... 實現一個能設定骰子點數出現機率的點數產生器 Ex. 執行產生50次點數 設定一點出現次數 10次 、 二點 10次、 三點 10次 四點 10次、五點 5次、六點 5次 產生的結果為亂數產生 1~6 點數並依照設定值產生各點數 次數 以下是部分程式.... class Mydice { //初始化陣列預設值為0 public static void init_arary(ref int[] target) { int i = 0; while (i < target.Length) { target[i] = 0; i++; } } //顯示陣列中所有值 public static void show(int[] data) { int i = 0; while (i < data.Length) { Console.Write("{0,-4}", data[i]); i++; } } //測試點數陣列是否已超過設定出現的次數 //參數 : int[] test 紀錄出現點數陣列 , int[] data 點數存放陣列 , int index 當次產生的點數(測試值) //傳回值 : 傳回bool值 public static bool test_val(int[] test , int[] data ,int index) { bool cond = false; if (test[index - 1] >= data[index - 1]) { cond = true; } return cond; } //產生隨機點數 //參數 : int[] numbers 設定各點數出現比率值, int total 點數產生次數 //傳回值 : 傳回整數陣列值 傳回點數出現統計陣列 public static int[] disc_generator(int[] numbers, int total) { //這邊不知道該怎麼寫...... } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.68.164.14
文章代碼(AID): #14AfW4Pm (C_Sharp)
文章代碼(AID): #14AfW4Pm (C_Sharp)