Basic-benchmark-experiment/TypeScript/code_unoptimised.js

22 lines
649 B
JavaScript
Raw Permalink Normal View History

2024-03-11 12:43:52 +02:00
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));