// kadai2-2.cpp
// ex) plot "???.txt" w boxes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

//ランダムウォークのステップ数
const int STEPS = 1000;

const int RANDOMS = 1000; //生成する乱数の個数
const int LOWER_LIMIT = 0; //ヒストグラムの下限と
const int UPPER_LIMIT = 10; //上限
const int DIVISION = 10; //分割数（1の幅をDIVISION等分）
const int HIST_MAX = (UPPER_LIMIT - LOWER_LIMIT) * DIVISION + 1;

//0以上1未満の一様乱数を生成する
double frand()
{
	return rand() / (RAND_MAX+1.0);
}

int main()
{
	double	y;
	int	i, step, h;

	//乱数を初期化する
	srand((unsigned int)time(NULL));

        //頻度を記録する配列、0で初期化
        int hist[HIST_MAX] = {0};

        for (i = 0; i < RANDOMS; i++) {
		//STEPSステップのランダムウォークを実施する
		y = 1.0;
		for (step = 0; step < STEPS; step++) {
			y = y * (0.9 + 0.2 * frand());
		}
		h = (int)(y * DIVISION);
		if (h < HIST_MAX) {
			hist[h]++;
		}
	}
        for (h = 0; h < HIST_MAX; h++) {
                printf("%4.1f %d\n", h / (double)DIVISION, hist[h]);
        }

	return 0;
}
