找回密碼 或 安全提問
 註冊
|註冊|登錄

伊莉討論區

搜索
請尊重及感激所有版主付出和奉獻尊貴會員無限使用任何功能伊莉需要你的贊助和支持
rion霹靂無碼流出ge 無碼旬果幼女惡靈古堡
棄屍ntr海と川のsecret j迷宮ノ花添い寝の借金返済

休閒聊天興趣交流學術文化旅遊交流飲食交流家庭事務PC GAMETV GAME
熱門線上其他線上感情感性寵物交流家族門派動漫交流貼圖分享BL/GL
音樂世界影視娛樂女性頻道潮流資訊BT下載區GB下載區下載分享短片
電腦資訊數碼產品手機交流交易廣場網站事務長篇小說體育運動時事經濟
上班一族博彩娛樂

[繁]海賊王 航海王 11

[簡]假面騎士GOTCHARD

快艇正妹豪乳吸睛

女子搧別人耳光的後果

[繁]迷宮飯12~15-

(4月新番)[繁]轉生為
C & C++ 語言C# 語言Visual Basic 語言PHP 語言JAVA 語言
查看: 3537|回復: 0
打印上一主題下一主題

[原創]C#不負責任之大樂透預測[複製鏈接]

Rank: 2Rank: 2

帖子
87
積分
217 點
潛水值
18862 米
跳轉到指定樓層
樓主
發表於 2013-12-25 09:59 PM|只看該作者|倒序瀏覽
所有積分大於負-100的壞孩子,將可獲得重新機會成為懲罰生,權限跟幼兒生一樣。
本帖最後由 cjoushua 於 2013-12-27 07:57 AM 編輯

題目:大樂透預測軟體
規則一:上一期出現過的號碼不再出現
規則二:依照歷史的統計機率去計算數字出現機率

這是小弟練習所寫的小範例,如果有更好的方法或是寫法請多多批評跟指教

第一期:

第二期:


草創版本規則尚待持續修正
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;

  9. namespace Lotto
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         public Form1()
  14.         {
  15.             InitializeComponent();
  16.         }

  17.         private void button1_Click(object sender, EventArgs e)
  18.         {
  19.             //By Joushua 20131226
  20.             //機率陣列(歷年以來每個數字出現的機率)
  21.             double[] probability = new double[] { 0.023947284, 0.023625844, 0.020411443, 0.020411443, 0.021215043, 0.018643523, 0.020090003, 0.022179364, 0.017357763, 0.018482803, 0.021536483, 0.019929283, 0.020090003, 0.018000643, 0.022179364, 0.020250723, 0.016393443, 0.018964963, 0.018000643, 0.019768563, 0.020250723, 0.022822244, 0.023143684, 0.018322083, 0.020572163, 0.021215043, 0.020090003, 0.023143684, 0.018000643, 0.021215043, 0.022982964, 0.018482803, 0.017679203, 0.019447123, 0.020090003, 0.022982964, 0.019286403, 0.021857923, 0.021536483, 0.018964963, 0.019286403, 0.020893603, 0.023304404, 0.020090003, 0.021375763, 0.020732883, 0.019607843, 0.020732883, 0.020411443 };

  22.             //取樣陣列
  23.             int[] sample = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 };

  24.             //rndold上一次的預測
  25.             ArrayList rndold = new ArrayList();

  26.             rndold.Add(Convert.ToInt32(label1.Text));
  27.             rndold.Add(Convert.ToInt32(label2.Text));
  28.             rndold.Add(Convert.ToInt32(label3.Text));
  29.             rndold.Add(Convert.ToInt32(label4.Text));
  30.             rndold.Add(Convert.ToInt32(label5.Text));
  31.             rndold.Add(Convert.ToInt32(label6.Text));
  32.             rndold.Add(Convert.ToInt32(label7.Text));

  33.             ArrayList rnd = MakeRand(sample,probability, 7, rndold);
  34.             rndold = rnd;
  35.             


  36.             label1.Text = zero(rnd[0].ToString());
  37.             label2.Text = zero(rnd[1].ToString());
  38.             label3.Text = zero(rnd[2].ToString());
  39.             label4.Text = zero(rnd[3].ToString());
  40.             label5.Text = zero(rnd[4].ToString());
  41.             label6.Text = zero(rnd[5].ToString());

  42.             //特別號
  43.             label13.Text = zero(rnd[6].ToString());



  44.             int[] arr = new int[] { Convert.ToInt32(label1.Text), Convert.ToInt32(label2.Text), Convert.ToInt32(label3.Text), Convert.ToInt32(label4.Text), Convert.ToInt32(label5.Text), Convert.ToInt32(label6.Text) };
  45.             sortm(arr);
  46.             label7.Text = zero(arr[0].ToString());
  47.             label8.Text = zero(arr[1].ToString());
  48.             label9.Text = zero(arr[2].ToString());
  49.             label10.Text = zero(arr[3].ToString());
  50.             label11.Text = zero(arr[4].ToString());
  51.             label12.Text = zero(arr[5].ToString());




  52.         }



  53.         //產生不重複的亂數
  54.         //sample 傳入陣列
  55.         //probability 陣列的機率
  56.         //intNum 產生亂數的數量
  57.         //rndold 上次的預測

  58.         private ArrayList MakeRand(int[] sample, double[] probability, int intNum,ArrayList rndold)
  59.         {
  60.             ArrayList arrayRand = new ArrayList();
  61.             //Random rnd = new Random((int)DateTime.Now.Ticks);
  62.             Random rnd = new Random();


  63.             int intRnd;
  64.             while (arrayRand.Count < intNum)
  65.             {
  66.                 intRnd = GetChance(rnd, sample, probability);

  67.                 //所產出的值不能在arrayRand內
  68.                 if (!arrayRand.Contains(intRnd))
  69.                 {
  70.                     //所產出的值不能在rndold內
  71.                     if (!rndold.Contains(intRnd))
  72.                     {
  73.                         arrayRand.Add(intRnd);
  74.                     }
  75.                 }
  76.             }
  77.             return arrayRand;
  78.         }

  79.         //個位數捕0
  80.         public string zero(string z)
  81.         {
  82.             if (z.Length < 2)
  83.             {
  84.                 z = "0" + z;
  85.             }
  86.             return z;
  87.         }


  88.         //從小排到大
  89.         public void sortm(int[] arr)
  90.         {

  91.             int arrbuff;

  92.             for (int i = 0; i <= arr.Length - 1; i++)
  93.             {

  94.                 for (int j = i + 1; j < arr.Length; j++)
  95.                 {

  96.                     if (arr[i] > arr[j])
  97.                     {

  98.                         arrbuff = arr[i];

  99.                         arr[i] = arr[j];

  100.                         arr[j] = arrbuff;

  101.                     }

  102.                 }
  103.             }

  104.             return;
  105.         }


  106.         //取得抽樣結果(帶入參數: 亂數物件, 取樣陣列, 機率陣列)
  107.         static int GetChance(Random rnd, int[] sample, double[] probability)
  108.         {
  109.             //機率陣列總和必須等於100
  110.             //if (probability.Sum() != 100) return -2;

  111.             //取樣陣列count必須等於機率陣列count
  112.             if (sample.Length != probability.Length) return -3;


  113.             double rndProbability = rnd.NextDouble();//傳回 0.0 和 1.0 之間的亂數。

  114.             double totalProbability = 0;
  115.             int itemIndex = 0;


  116.             foreach (double p in probability)
  117.             {
  118.                 //0=0+機率陣列內的probability[p]
  119.                 totalProbability += p;

  120.                 //totalProbability = totalProbability + probability[p]直到超過亂數的值
  121.                 if (totalProbability >= rndProbability )

  122.                     //回傳取樣陣列的結果值
  123.                     return sample[itemIndex];

  124.                 //0=0+1
  125.                 itemIndex++;
  126.             }

  127.             return -1;

  128.         }
  129.     }
  130. }
複製代碼





...
瀏覽完整內容,請先 註冊登入會員
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊
分享分享0收藏收藏0支持支持0
所有積分大於負-100的壞孩子,將可獲得重新機會成為懲罰生,權限跟幼兒生一樣。

使用道具檢舉

您需要登錄後才可以回帖 登錄 | 註冊

Powered by Discuz!

© Comsenz Inc.

重要聲明:本討論區是以即時上載留言的方式運作,對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿上傳和撰寫 侵犯版權(未經授權)、粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。
回頂部