#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define HISTSIZE	100
#define BUFSIZE		100

// 正規乱数
double normrand(void)
{
	double	ra, rb, nr;

	ra = (double)rand() / RAND_MAX;
	rb = (double)rand() / RAND_MAX;
	nr = sqrt(-2.0 * log(ra)) * cos(2.0 * M_PI * rb);
	return nr;
}

int main()
{
	int	hist[HISTSIZE] = {0};
	char	buf[BUFSIZE];
	double	x, y, d;
	int	i, s, h;

	srand(time(NULL));
	memset(buf, '*', BUFSIZE);

	for (i = 0; i < 1000; i++) {
		x = y = 0.0;
		for (s = 0; s < 1000; s++) {
			x += normrand();
			y += normrand();
		}
		d = sqrt(x * x + y * y);
		printf("%5.1f%c", d, (i+1)%10?' ':'\n');
		h = d;
		if (h < HISTSIZE) {
			hist[h]++;
		}
	}
	for (i = 0; i < HISTSIZE; i++) {
		h = hist[i];
		if (BUFSIZE < h) h = BUFSIZE;
		printf("%3d %3d %.*s\n", i, hist[i], h, buf);
	}
	return 0;
}
