Last active
August 9, 2019 08:57
-
-
Save SiAce/0a5ffadc0b58023ece037de16eb91c99 to your computer and use it in GitHub Desktop.
Calculate Pseudo Random for Dota 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Calculate Pseudo Random for Dota 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const runs = 10000000; | |
const chance = 0.25; | |
const baseChance = 0.085; | |
let pseudoChance = baseChance; | |
let sum = 0; | |
for (let i = 0; i < runs; i++) { | |
const num = Math.random(); | |
if (num < pseudoChance) { | |
pseudoChance = baseChance; | |
sum++; | |
} else { | |
pseudoChance += baseChance; | |
} | |
} | |
console.log(sum / runs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const runs = 100000000; | |
const p = 0.2; | |
const times = []; | |
let time = 1; | |
let sum = 0; | |
for (let i = 0; i < runs; i++) { | |
const num = Math.random(); | |
if (num < p) { | |
times.push(time); | |
time = 1; | |
} else { | |
time++; | |
} | |
} | |
times.forEach((element) => { | |
sum += element; | |
}); | |
console.log(sum / (times.length)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment