Skip to content

Instantly share code, notes, and snippets.

@mironal
Created June 20, 2012 05:46
Show Gist options
  • Save mironal/2958321 to your computer and use it in GitHub Desktop.
Save mironal/2958321 to your computer and use it in GitHub Desktop.
<script>
/* 乱数の発生具合を調べる */
var loop = 1000000;
var rslt = new Array(50); /* 0 から (rslt.length - 1)までの乱数 */
for(var i = 0; i < loop; i++){
/* 乱数生成 */
var r = Math.floor(Math.random() * rslt.length);
if(!rslt[r]){
rslt[r] = 1;
}else{
rslt[r]= rslt[r] + 1;
}
}
for(var i = 0; i < rslt.length; i++){
if( Math.abs(rslt[i] - (loop / rslt.length)) > ((loop /rslt.length) / 10)){
console.log("NG : rslt[" + i + "] = " + rslt[i]);
}
//console.log( i + " : " + rslt[i]);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment