2024年11月6日 星期三

訓練數學感 387 ─ 中獎機率

https://4rdp.blogspot.com/2024/11/387.html


如圖所示,求機率。

難度 

最近看到羅智強在立法院質詢財政部「雲端種樹趣 e 起集點樹」抽獎的問題,有四個人竟然連中兩次大獎,這種幾乎不可能出現的機率,竟然發生!發生在某一個人就算,可是卻有四個人,告訴我抽獎過程完全公平沒問題,應該沒有人會相信,今年多項行政作為根本是在破壞人民對政府的信賴,尤其是大法官對死刑以及國會改革的釋憲。

3 則留言:

  1. 改为从9人中抽奖,概率大约是0.0636 :)

    回覆刪除
    回覆
    1. 謝謝提供程式來估算機率,不過這方法在計算特定四個人

      刪除
  2. # Revised approach: Reducing the number of trials and tracking only the necessary outcomes to speed up simulation
    import numpy as np
    num_people = 9
    num_target_people = 4
    prizes_per_round = [5,5,9]
    target_wins = 2
    # Adjusted parameters for a quicker estimation
    num_trials = 10**6 # Reduced number of simulations for faster runtime

    # Function to simulate one trial
    def simulate_trial():
    # Draw winners for each round
    winners_round_1 = set(np.random.choice(num_people, prizes_per_round[0], replace=False))
    winners_round_2 = set(np.random.choice(num_people, prizes_per_round[1], replace=False))
    winners_round_3 = set(np.random.choice(num_people, prizes_per_round[2], replace=False))

    # Track each target person's wins
    wins = [0] * num_target_people
    for i in range(num_target_people):
    person_id = i # IDs 0, 1, 2, 3 for the target people
    wins[i] += person_id in winners_round_1
    wins[i] += person_id in winners_round_2
    wins[i] += person_id in winners_round_3

    # Check if exactly 4 people have exactly 2 wins
    return sum(win == target_wins for win in wins) == num_target_people

    # Run the simulation over the specified number of trials
    target_people_wins = 0
    for i in range(1,num_trials+1):
    target_people_wins += simulate_trial()
    # Calculate probability
    probability_estimate = target_people_wins / i
    print(probability_estimate,"")

    回覆刪除