2016-11-16 9 views
1

私は都市の人口の100行を生成し、各都市に対して同じ数の失業者の列を生成する必要があります。データは実際のものに近いはずです。私の質問は、それをどうやって行うのかです。アイデアがあり、あなたの意見を得るためにあなたと共有したいと思います。例:母集団に関するデータの生成方法

セントラル統計局の特定の都市で200行の真の母集団データを取得し、これらの200行から無作為に100を選択します。その後、失業者のデータを無作為に生成するが、失業者数が人口を超えないことを考慮して、早期の人口データに基づいている。

この時点で私はこのような(集団について)1000年から30 000の範囲のデータをランダムに生成されています:

int random_population_result = (rand() % 29000) + 1000; 

と失業者100〜2000の範囲

int random_unemployed_result = (rand() % 1900) + 100; 

が、私の教授は私にこのようなデータを生成させるのは良い考えではないと思ったので、私はそれについて考えさせました。私はあなたに上記の新しいアイデアを紹介しました。私はあなたの意見に興味があります。

ループ全体:

//number of rows in column 
const int colSize = 100; 
int col_X[colSize]; //stores X values [population] 
int col_Y[colSize]; //stores Y values [unemployed people] 
//display table header 
cout << "id " << "\t" << "X" << "\t" << "Y" << endl; 
for (int i = 0; i < colSize; i++){ 
    //return value between 1000 and 30 000 of population 
    int random_population_result = (rand() % 30000) + 1000; 
    //return value between 100 and 2000 of unemployed people 
    int random_unemployed_result = (rand() % 1900) + 100; 
    //put values to arrays 
    col_X[i] = random_population_result; 
    col_Y[i] = random_unemployed_result; 
} 

よろしく。

+0

ヨーヨーが何でしたかああ、以前の方法?どういう意味ですか?あなたの教授はそれについて何か他のことを言いましたか? –

+1

ちょうどコメント:深刻なランダム性が必要な場合は、 'rand()'を使わないでください。なぜ[ここ](http://stackoverflow.com/questions/26440252/is-rand-really-that-bad)を参照してください。代わりに[''](http://en.cppreference。com/w/cpp/header/random) – kebs

+0

あなたの本当の人口データは都市別の失業率の値を持っていますか? – pjs

答えて

1

user3386109が言っているように、現実的なデータセットが必要な場合があります。まず

は、あなたが、

int random_population_result = (rand() % 30000) + 1000; 
int random_unemployed_result = (rand() % (random_population_result-100)) + 100; 

しかしそう、人口の結果に基づいて、あなたの失業を作成したいあなたは失業率が1%と20%の間の範囲だけができることを考慮に入れたい場合は、次を追加します。

int minPercent = 1; 
int maxPercent = 20; 
int random_population_result = (rand() % 30000) + 1000; 
int random_unemployed_result = (rand() % ((maxPercent-minPercent)*random_population_result/100)) + minPercent*random_population_result/100; 

ので、更新結果は次のようになります。

int col_X[colSize]; //stores X values [population] 
int col_Y[colSize]; //stores Y values [unemployed people] 

//display table header 
//cout << "id " << "\t" << "X" << "\t" << "Y" << endl; 
for (int i = 0; i < colSize; i++){ 
    //return value between 1000 and 30 000 of population 
    //(ile_liczb_w_przedziale) + startowa_liczba; 
    int minPercent = 1; 
    int maxPercent = 20; 
    int random_population_result = (rand() % 30000) + 1000; 
    int random_unemployed_result = (rand() % ((maxPercent-minPercent)*random_population_result/100)) + minPercent*random_population_result/100; 
    //put values to arrays 
    col_X[i] = random_population_result; 
    col_Y[i] = random_unemployed_result; 
} 
2

極端を見てください。最も小さい人口は1000人であり、最大の失業率は2000人です。それは1000人の人口で2000人の失業者を雇うことができないので、明らかに問題です。

都市では100人の失業者これは失業率0.3%である。それはあなたが実生活で見つけるよりもはるかに低いです。

したがって、失業の結果は都市人口に比例するはずです。実生活では、失業率は一般に人口のパーセンテージとして表され、都市ごとにわずかな違いがあります。例えば、平均失業率は10%、都市Aは失業率9%、都市Bは12%を占める可能性があります。

都市の人口を選択し、失業率を選択し、2つの結果を掛けて失業者数を求めます。

関連する問題