フィルターのクリア

Choose random between two option.

56 ビュー (過去 30 日間)
Giselle
Giselle 2017 年 3 月 23 日
コメント済み: Valerie Reinisch 2020 年 12 月 22 日

Hi, i want to choose randomly between the "boy" or "girl", how can i do that? Each has the same probability of 50%.

i want to calculate this question:

In a country in which people only want boys … … every family continues to have children until they have a boy. If they have a girl, they have another child. If they have a boy, they stop. What is the proportion of boys to girls in the country? Tnx

回答 (2 件)

Image Analyst
Image Analyst 2017 年 3 月 23 日
Hint:
sexes = {'Boy', 'Girl'};
r = randi([1, 2], 1) % Get a 1 or 2 randomly.
thisSex = sexes(r) % Extract the sex for this random number.
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 22 日
編集済み: Walter Roberson 2020 年 12 月 22 日
r = rand() > 0.60
thisSex = sexes{r+1}
By the way: my modeling says 2/3 girls on average.
Valerie Reinisch
Valerie Reinisch 2020 年 12 月 22 日
Tried it in the meanwhile with this:
r = binornd(1,0.6)
But thanks a lot for this quick answer! (:

サインインしてコメントする。


Roger Stafford
Roger Stafford 2017 年 3 月 23 日
編集済み: Roger Stafford 2017 年 3 月 23 日
There should be no need to go through such a simulation. For each birth the probability that a boy is born is one-half regardless of all the tricks the family may play.
However if you are addicted to more complicated computations, the average number of boys per family is:
1/2*1 + 1/4*1 + 1/8*1 + ... = 1
and the average number of girls per family is:
1/2*0 + 1/4*1 + 1/8*2 + 1/16*3 + 1/32*4 + ... = 1
You can use symsum to verify these.
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 22 日
trials = 1E6;
isboy = rand(trials,53) <= 0.5;
child_number_for_boy = sum(cumprod(~isboy,2),2) + 1;
avg_number_of_girls = mean(child_number_for_boy - 1)
avg_number_of_girls = 0.9988
max_number_of_girls = max(child_number_for_boy) - 1
max_number_of_girls = 20

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeR Language についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by