Skip to content

Instantly share code, notes, and snippets.

@fwg
Forked from memowe/gist:271270
Created January 7, 2010 15:05
Show Gist options
  • Save fwg/271277 to your computer and use it in GitHub Desktop.
Save fwg/271277 to your computer and use it in GitHub Desktop.
function drawProgress (factor) {
var progress = $('#progress');
var bar = progress.children('#bar');
var maxwidth = progress.width();
factor = factor > 1 ? 1 : factor < 0 ? 0 : factor;
bar.width( maxwidth * factor );
}
function calculate (params) {
var schwarze = new Array();
var iter = 1;
(function f(){
if (iter <= params.anzahl) { // Stichprobe
iter++;
var schw = 0;
for ( var i = 1; i <= params.stichprobe; i++ ) { // Ziehung
var zuf = 1 + Math.floor( Math.random() * params.kugeln );
if ( zuf <= params.skugeln ) {
schw += 1;
}
}
schwarze.push(schw);
drawProgress( iter / params.anzahl );
setTimeout(f,0);
}
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment