Basic-benchmark-experiment/TypeScript/code_unoptimised.js

22 lines
649 B
JavaScript

var total_attempts = 15000000;
var successful_attempts = 0;
var get_random = function () {
return Math.floor(Math.random() * 256);
};
for (var i = 0; i < total_attempts; i++) {
/*
var a = Math.floor(Math.random() * 256);
var b = Math.floor(Math.random() * 256);
var c = Math.floor(Math.random() * 256);
*/
var a = get_random();
var b = get_random();
var c = get_random();
if (a + b + c > 300) {
successful_attempts++;
}
}
console.log("Iterations: " + total_attempts);
console.log("Successful checks: " + successful_attempts);
console.log("Probability: " + (successful_attempts / total_attempts));