#include <iostream.h>
#include <stdlib.h>
#include <mylib.h>
#include <math.h>

main(int argc, char **argv)
{
 argc--, argv++;
 unsigned size = argc>0 ? atoi(*argv) : 30000;
 argc--, argv++;

 unsigned mx, mn;

 mx = mn = uniform(size);
 int i;
 for(i=0;i<10000;i++)	{
	unsigned tmp = uniform(size);
	if(tmp > mx)	mx = tmp;
	if(tmp < mn)	mn = tmp;
	}
 cout << "after " << i << " passes, max=" << mx << " min = " << mn << endl;
  long avg = (mx+mn)/2;
 double sum = 0.0;
 for(i=0;i<1000;i++)	{
		 long x = 0;
		 int j;
		 for(j=0;j<100;j++)
			x += uniform(size) - avg;
		sum += x;
		cout << "x = " << x << endl;
		}
 cout << "sum = " << sum << endl;
 exit(0);
}
