29 lines
609 B
JavaScript
29 lines
609 B
JavaScript
const total_attempts = 15000000;
|
|
var successful_attempts = 0;
|
|
|
|
var get_random = () => {
|
|
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));
|