23 lines
584 B
Text
23 lines
584 B
Text
rnormal()={
|
|
my(u1=random(1.),u2=random(1.));
|
|
sqrt(-2*log(u1))*cos(2*Pi*u2)
|
|
\\ Could easily be extended with a second normal at very little cost.
|
|
};
|
|
mean(v)={
|
|
sum(i=1,#v,v[i])/#v
|
|
};
|
|
stdev(v,mu="")={
|
|
if(mu=="",mu=mean(v));
|
|
sqrt(sum(i=1,#v,(v[i]-mu)^2))/#v
|
|
};
|
|
histogram(v,bins=16,low=0,high=1)={
|
|
my(u=vector(bins),width=(high-low)/bins);
|
|
for(i=1,#v,u[(v[i]-low)\width+1]++);
|
|
u
|
|
};
|
|
show(n)={
|
|
my(v=vector(n,i,rnormal()),m=mean(v),s=stdev(v,m),h,sz=ceil(n/300));
|
|
h=histogram(v,,vecmin(v)-.1,vecmax(v)+.1);
|
|
for(i=1,#h,for(j=1,h[i]\sz,print1("#"));print());
|
|
};
|
|
show(10^4)
|