var c = new Array();
function sample(){
n = 5;
p = 0.5;
for (s = 0; s < 6;s++ ){
c[s] = 0;
}
for (tr = 1; tr < 10000; tr++) {
x = 0;
for (s = 1; s < n + 1; s++) {
if (Math.random() < p) x = x + 1;
}
c[x] = c[x] + 1;
}
paint();
}
function paint(){
var sub=new svgpaint();
var maxc = 0;
for(s=0;s<6;s++){
if(c[s]>maxc)maxc=c[s];
}
str="<svg width=\"500\" height=\"500\">";
for(s=0;s<6;s++){
x1=500*c[s]/maxc
str=str+sub.rect(90*s,500-x1,90,x1,"blue");
}
str=str+"</svg>";
$("#memo").html(str);
}
最終更新:2016年04月01日 18:20