最近看到羅智強在立法院質詢財政部「雲端種樹趣 e 起集點樹」抽獎的問題,有四個人竟然連中兩次大獎,這種幾乎不可能出現的機率,竟然發生!發生在某一個人就算,可是卻有四個人,告訴我抽獎過程完全公平沒問題,應該沒有人會相信,今年多項行政作為根本是在破壞人民對政府的信賴,尤其是大法官對死刑以及國會改革的釋憲。
# 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,"")
母雞、福特汽車、手帕。那些喚起性衝動的奇妙物品
-
什麼東西能夠引發性慾呢?綜觀歷史,
有許多超乎想像的答案被記下來,母雞、汽車、手帕都成為性慾來源,這些怪怪的「性偏好」是如何性成的呢?又一定需要治療嗎?
The post 母雞、福特汽車、手帕。那些喚起性衝動的奇妙物品 appeared first on PanSci 泛科學.
改为从9人中抽奖,概率大约是0.0636 :)
回覆刪除謝謝提供程式來估算機率,不過這方法在計算特定四個人
刪除# 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,"")